Find the error(s) in each of the following, and explain how to correct it (them):
a) ```
string string1( 28 ); // construct string1
string string2( 'z' ); // construct string2
```
b) ```
// assume std namespace is known
const char *ptr = name.data(); // name is "joe bob"
ptr[ 3 ] = '-';
cout << ptr << endl;
```
a) Constructors for class string do not exist for integer and character arguments. Other valid constructors should be used—converting the arguments to strings if need be.
b) 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;
You might also like to view...
Iterative solutions are always possible. Why then, would we bother with recursive solutions to problems? What advantages do some recursive algorithms have over the iterative versions?
What will be an ideal response?
The Border button and the Shading button are located in the _____ group on the HOME tab.
A. Editing B. Illustrations C. Paragraph D. Preview
Border widths can be expressed using the keywords ____, medium, or thick.
A. thin B. auto C. average D. slim
A TIFF is a graphic format that can store up to 16.7 million colors
Indicate whether the statement is true or false