Answers to Self-Review Exercises
-
<string>
.std
.erase
.find_first_of
.
-
True.
True.
True.
False. A
string
is an object that provides many different services. A pointer-based string does not provide any services. Pointer-based strings are null terminated;string
s are not necessarily null terminated. Pointer-based strings are pointers andstring
s are objects.
-
Constructors for class
string
do not exist for integer and character arguments. Other valid constructors should be used—converting the arguments tostring
s if need be.Function
data
does not add a null terminator. Also, the code attempts to modify aconst char
. Replace all of the lines with the code:cout << name.substr(0, 3) + "-" + name.substr(4) << endl;
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.