Localization: example from document page doesn't work for latin characters ?
Jan Pfeifer
pfjan@yahoo.com.br
Sun Dec 11 13:08:00 GMT 2005
hi again,
I was trying the example from the docs, for character transformation
(touppper/lower):
http://gcc.gnu.org/onlinedocs/libstdc++/22_locale/howto.html#7
But I noticed it doesn't work. From the example in the page -- see code
in the end of email --, I get the following transformations:
Ãrfão (normal string, "orphan" in portuguese)
ÃRFãO (should be upper case)
Ãrfão (should be lower case)
Am I missing something, or is there something missing in the library ?
thanks!
jan
ps.: the source code:
#include <iostream>
#include <iterator> // for back_inserter
#include <locale>
#include <string>
#include <algorithm>
#include <cctype> // old <ctype.h>
using namespace std;
struct MyToUpper
{
MyToUpper(std::locale const& l) : loc(l) {;}
char operator() (char c) const { return std::toupper(c,loc); }
private:
std::locale const& loc;
};
struct MyToLower
{
MyToLower(std::locale const& l) : loc(l) {;}
char operator() (char c) const { return std::tolower(c,loc); }
private:
std::locale const& loc;
};
int main(int argc, char** argv)
{
// locale loc( "" );
// locale loc( "en_US.UTF-8" );
locale loc( "pt_BR.UTF-8" );
MyToUpper up( loc );
MyToLower down( loc );
string normal = "Ãrfão";
cout << normal << endl;
transform( normal.begin(), normal.end(), normal.begin(), up );
cout << normal << endl;
transform( normal.begin(), normal.end(), normal.begin(), down );
cout << normal << endl;
return 0;
}
_______________________________________________________
Yahoo! doce lar. Faça do Yahoo! sua homepage.
http://br.yahoo.com/homepageset.html
More information about the Libstdc++
mailing list