This post will discuss how to convert the first letter of a string to uppercase in C++.

1. Using toupper() function

The standard solution to convert a lowercase letter to uppercase is using the toupper() function from <cctype> header. The idea is to extract the first letter from the given string, and convert it to uppercase. This works in-place, since strings are mutable in C++.

Download  Run Code

2. Using std::transform

To capitalize the first letter and lowercase the rest, use the std::transform from the standard library. The idea is to lowercase the complete string and then convert the first letter to uppercase.

Download  Run Code

 
We can further shorten the above code with tolower from the global namespace which can be directly referenced with a name, as shown below:

Download  Run Code

That’s all about converting the first letter of a string to uppercase in C++.