View Full Version : uppercase method
tricolaire
08-02-2005, 12:23 AM
I'm using the g++ c++ compiler, and I need a method to convert a string to all uppercase characters. the string class doesn't seem to contain one, at least, not one that I've been able to find. please help!
sage45
08-02-2005, 03:43 AM
One method I use:#include <algorithm>
#include <string>
using namespace std;
int main()
{
string s="hello";
transform(s.begin(), s.end(), s.begin(), (int(*)(int)) toupper);
}Another way of doing it is like this:#include <string>
using namespace std;
int main()
{
string s="hello";
for (int j=0; j<s.length(); ++j)
{
s[j]=toupper(s[j]);
}
}HTH,
-sage-
tricolaire
08-02-2005, 07:04 PM
fair enough, I thank you
but where (what header) does the function toupper come from?
oracleguy
08-02-2005, 09:01 PM
I think it is in iomanip but I could be wrong.
sage45
08-04-2005, 01:48 AM
toupper is actually in the STDLIB or CTYPE headers... ;)
-sage-
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.