Is there a way to use toUpper with a string, or do you have to loop it through an array of chars? Ive been googling everywhere, but havent really found any examples on how to properly use it. Thanks

>Ive been googling everywhere, but havent really
>found any examples on how to properly use it.

I suspect what you found is what most of us would tell you:

for (string::size_type i = 0; i < s.size(); i++)
  s[i] = std::toupper((unsigned char)s[i]);

You'll probably also find the broken:

std::transform(s.begin(), s.end(), s.begin(), std::toupper);

And variations of the corrected version:

template <typename CharT>
struct Upper {
  CharT operator()(CharT c)
  {
    return (CharT)std::toupper((unsigned char)c);
  }
};

std::transform(s.begin(), s.end(), s.begin(), Upper<char>());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.