Q:

So long as the string is not const (§ 2.4, p. 59), we can assign a new value to the character that the subscript operator returns. For example, we can capitalize the first letter as follows

0

So long as the string is not const (§ 2.4, p. 59), we can assign a new value to the character that the subscript operator returns. For example, we can capitalize the first letter as follows.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

string s("some string");
if (!s.empty()) // make sure there's a character in s[0]
s[0] = toupper(s[0]); // assign a new value to the first character in s

 

Output:

Some string

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now