Basic facilities, Part 1
- slide 17 : 28
C++ style strings
It is recommended to use type
string
instead of the low-level
char*
or
char[]
The C++ Prog. Lang. (3. edition)
:
Page 48-49, 579
The C++ Prog. Lang. (4. edition)
: Page 90-91, 1033
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