Main Page

Previous Page
Next Page

[Page 907 (continued)]

Self-Review Exercises


Fill in the blanks in each of the following:

  1. Header ___________ must be included for class string.

  2. Class string belongs to the ______________ namespace.

  3. Function ___________ deletes characters from a string.

  4. Function ___________ finds the first occurrence of any character from a string.


State which of the following statements are true and which are false. If a statement is false, explain why.

  1. Concatenation of string objects can be performed with the addition assignment operator, +=.

  2. Characters within a string begin at index 0.

  3. The assignment operator, =, copies a string.

  4. A C-style string is a string object.

[Page 908]

Find the error(s) in each of the following, and explain how to correct it (them):

  1.  string string1( 28 ); // construct string1
     string string2( 'z' ); // construct string2

  2.  // assume std namespace is known
     const char *ptr = name.data(); // name is "joe bob"
     ptr[ 3 ] = '-';
     cout << ptr << endl;

Previous Page
Next Page