Convert first letter in string to uppercase

user1065276 picture user1065276 · Dec 16, 2011 · Viewed 79.7k times · Source

I have a string: "apple". How can I convert only the first character to uppercase and get a new string in the form of "Apple"?

I can also have a string with multibyte characters.

What if the first character of the string is a multibyte character ?

Answer

Seth Carnegie picture Seth Carnegie · Dec 16, 2011
string str = "something";
str[0] = toupper(str[0]);

That's all you need to do. It also works for C strings.