Basic facilities
- slide 13 : 42
C++ style strings
It is recommended to use type
string
instead of the low-level
char*
or
char[]
The C++ Programming Language
: Page 48-49, 579
Type
string
in C++:
string
is alias for a
basic_string
parameterized by
char:
typedef basic_string<char> string
Strings obey
value semantics
Copied in and out of functions
Characters in strings can be accessed in
checked mode
and
unchecked mode
:
Checked mode:
s.at(i)
Unchecked mode:
s[i]
A string is
mutable
Strings can be
copy constructed
based on a C-style string
string s("Peter");
or
string t = "Peter";
The
basic_string
class supports a large number of string operations