C++ — Convert string to upper/lower case

By Rares Vernica

To convert an std::string to upper case you can use the following:

#include <algorithm>
#include <string>

std::string data = “Abc”;
std::transform(data.begin(), data.end(),
data.begin(), ::toupper);

For converting to lower case, you need to replace ::toupper with ::tolower.

Leave a Reply

You must be logged in to post a comment.