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
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;
```

Computer Science & Information Technology

You might also like to view...

The numbers that identify the rows of a worksheet are called the labels

Indicate whether the statement is true or false

Computer Science & Information Technology

A(n) ____ is a collection of elements (people, hardware, software, and data) and procedures that interact to generate information needed by the users in an organization.

A. operating system B. information system C. device D. utility program

Computer Science & Information Technology