This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Imbue does not honour encoding


Hi I don't know whether this is a feature or a bug but I suspect it to
be the latter. When I imbue a wstream with a UTF-8 locale the encoding
part of the locale doesn't seem to be honoured. Consider the following
wcin.cc:

#include <iostream>
#include <string>
#include <locale>
using namespace std;

float f;
wstring euro;

int main(){
        locale l("de_DE.UTF-8");
        wcin.imbue(l);
        locale::global(l); // (*)
        wcin>>f>>euro;
        wcout.imbue(locale("en_US.UTF-8"));
        wcout<<f<<L" "<<euro<<endl;
}

Calling "echo 5,70 â|./wcin" (in a UTF-8 environment) results in the
correct output

5.7 â

But if I omit the line marked (*) the euro sign cannot be read in
although wcin has been imbued with a UTF-8 locale. According to
Stroustrup, the setting of the global locale does not affect existing
input/output streams. But according to my tests the encoding of a stream
is always the encoding of the current global locale.

I use the following library on a i386 computer

~> rpm -qi libstdc++
Name		: libstdc++                   
Version		: 4.1.0        
Vendor		: SUSE LINUX Products GmbH, Nuernberg, Germany
Release		: 25                            
Build Date	: Sa 29 Apr 2006 01:16:41 CEST
Install Date: Mo 29 Mai 2006 12:46:11 CEST
Group       : System/Libraries
Source RPM	: gcc-4.1.0-25.src.rpm
Summary     : The standard C++ shared library





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]