Convert a String In C++ To Upper Case


Question

How could one convert a string to upper case. The examples I have found from googling only have to deal with chars.

1
250
7/17/2012 12:31:59 PM

Accepted Answer

Boost string algorithms:

#include <boost/algorithm/string.hpp>
#include <string>

std::string str = "Hello World";

boost::to_upper(str);

std::string newstr = boost::to_upper_copy<std::string>("Hello World");
202
5/14/2015 3:06:54 AM

#include <algorithm>
#include <string>

std::string str = "Hello World";
std::transform(str.begin(), str.end(),str.begin(), ::toupper);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon