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...
IPv6 uses six groups of 16-bit numbers
Indicate whether the statement is true or false
You updated Group Policy so that you can use BitLocker without a TPM. You want to apply Group Policy immediately. How do you accomplish this?
a. Close the Group Policy Editor, and it will be applied immediately. b. Run gpedit.msc. c. Run Gpupdate /force. d. Reboot the computer.