C++ and CS106 Library Reference
Written by Julie Zelenski.
A couple of decent C++ web resources you might want to bookmark:
These can be useful for anything in standard C++, which includes the language itself and
all of its standard libraries (
The standard C++
The string class is defined in
type is actually a
shorthand. The underlying full name is
You don’t need to worry about this sort of low-level goop, but you will see the full name in
compiler error messages and will want to recognize it as such.
The default constructor initializes a string variable to the empty string, thus declaring a
string variable ensures that its contents start empty.
This is unlike the built-in types (
, etc.) that have random contents until explicitly initialized. Assigning one string to
or passing/returning a string makes a new distinct copy of the same character
sequence. Strings are mutable, unlike Java strings.
A string literal, i.e., sequence of characters within double-quotes such as
actually an old-style C-string.
You can typically use a C-string wherever a string object is
required since there is an automatic conversion from C-string to new-style C++ string
If ever need to force this conversion, you can do so using a syntax similar to a
This is invoking the string class constructor that takes a
In general, operations on strings are designed to be very efficient and, as a result, some do
not check parameters for validity.
It is the client's job to ensure positions/lengths are in
bounds for calls to
, find, replace, and so on.
The behavior on incorrect calls is
implementation-dependent, but unlikely to be pleasant in any situation.