That won't compile if you #include <locale> (since then toupper is
overloaded). In addition, it has undefined behaviour if s has any
negative characters in it (the domain of toupper is 0-UCHAR_MAX and EOF).
I'd pull the facet creation out of the loop. e.g.
std::ctype<char> const& ct =
for (std::string::iterator p = s.begin(); p != s.end(); ++p)
*p = ct.toupper(*p);
//need target type since toupper is overloaded.
char (std::ctype<char>::*fptr)(char) const = &std::ctype<char>::toupper;
However, it may well run slower than the loop, if it fails to inline the
member function calls. It's also less clear than the loop. Finally,
there is also a non-member function in <locale>
char toupper(char, std::locale const&); //actually, it's templated IIRC
However, I'd generally avoid these machinations and instead use the
boost string library: http://www.yqcomputer.com/
I think so.
It is explicitly defined as legal to modify the argv strings in the C
standard, though the C++ standard doesn't say anything about whether you
can modify them.