C++ standard wide iostreams code conversion - outputs garbage
Hello all,
I am trying to have a C++ program output unicode strings on std::wcout. I use a UTF-8 based locale (either fr_FR.UTF-8 or en_US.UTF-8). The following code Code:
#include <iostream> The C equivalent works perfectly though: Code:
#include <assert.h> Code:
#include <cassert> |
operating system?
|
I run Gentoo Linux with gcc 4.3.2 and Ubuntu Linux with gcc 4.3.3 and both are affected.
|
Have you tried compiling the C one with g++? I'd like to know what happens in that case.
Kevin Barry |
Interestingly, it works if the global locale is set before the stream is used, ie
Code:
std::locale::global(std::locale("fr_FR.UTF-8")); That would be painful if you wanted to have streams with different locales. ---edit--- ah, explanation here Turning off the standard stream synchronization at the start of the program is a nicer way to get the desired behaviour: Code:
std::ios::sync_with_stdio(false); |
@ta0kira
gcc or g++ are both affected. @neonsignal Thank you, that fixed it! That was a nasty one. I suppose the compromise the libstdc++ devs made makes sense, but I wish they documented it clearly. |
All times are GMT -5. The time now is 09:12 AM. |