This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Localization: example from document page doesn't work for latin characters ?
- From: Jan Pfeifer <pfjan at yahoo dot com dot br>
- To: libstdc++ at gcc dot gnu dot org
- Date: Sun, 11 Dec 2005 11:08:13 -0200
- Subject: Localization: example from document page doesn't work for latin characters ?
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