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.
Other C/C++ not so frequently asked questions.
December 26, 2011 at 7:47 pm |
top selling guitar…
[...]C++ — Convert string to upper/lower case « Not So Frequently Asked Questions[...]…
December 28, 2011 at 11:36 pm |
les paul…
[...]C++ — Convert string to upper/lower case « Not So Frequently Asked Questions[...]…
March 28, 2013 at 11:43 pm |
[...] From http://notfaq.wordpress.com/2007/08/04/cc-convert-string-to-upperlower-case/: [...]
March 29, 2013 at 8:12 am |
tolower takes an int; std::string contains potentially unsigned chars, in which case the code above would be buggy.
=> missing static_cast!