Click to See Complete Forum and Search --> : string to upper case


Gamut
October 11th, 2002, 09:48 AM
Gurus,
Is there a function in gcc which would convert a STRING (std::string) to upper case?

Thanks in Advance

Philip Nicoletti
October 11th, 2002, 10:06 AM
std::transform() should work. I have two versions
of g++. On one it works, on another (older) it has
a compiler error.



#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(int argc, char* argv[])
{

string str = "Hello World";

transform(str.begin(),str.end(), str.begin() , toupper);

cout << str << endl;

return 0;
}

Waldo2k2
October 11th, 2002, 10:50 AM
if you can use the windows.h header, use

ToUpper(const char*);

Gamut
October 11th, 2002, 11:03 AM
thanks

Waldo2k2
October 11th, 2002, 11:17 AM
oops, i made a mistake...
it's

CharUpper(const char*);