Main Page

Previous Page
Next Page

[Page 908 (continued)]

Answers to Self-Review Exercises


a)<string>. b) std. c) erase. d) find_first_of.

  1. True.

  2. True.

  3. True.

  4. False. A string is an object that provides many different services. A C-style string does not provide any services. C-style strings are null terminated; strings are not necessarily null terminated. C-style strings are pointers and strings are not.

  1. Constructors for class string do not exist for integer and character arguments. Other valid constructors should be usedconverting the arguments to strings if need be.

  2. Function data does not add a null terminator. Also, the code attempts to modify a const char. Replace all of the lines with the code:

    cout << name.substr( 0, 3 ) + "-" + name.substr( 4 ) << endl;

Previous Page
Next Page