help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in C++ locales and streams?


From: Roger Leigh
Subject: Bug in C++ locales and streams?
Date: Fri, 26 Nov 2004 23:48:46 +0000
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Using the example code below, the output is as follows (Debian
GNU/Linux, GCC 3.4.3, glibc 2.3.2):

$ ./test
Umlaute: ??ss

If I uncomment the std::locale::global line, I get this:

$ ./test
Umlaute: ïüß

In both cases, the user's locale is en_GB UTF-8, and the de_DE locale
is also using UTF-8 as its codeset.  The program was compiled as
follows:

g++-3.4 -finput-charset=UTF-8 -o test test.cc


What's worrying me is the need to set up the global locale.  Surely
imbuing the correct locale in the std::wcout stream should be
sufficient?  In fact, commenting out the imbue step (keeping the
std::locale::global line uncommented) doesn't show any difference in
output.

Without std::locale::global set, it looks like the locale is C, and
the stream is iconv()ed to US-ASCII, which turns ß to ss, but can't
represent ï and ü.

Is this a bug?  Is the imbued locale having any effect whatsoever?


Many thanks,
Roger

[test.cc, UTF-8 encoded]
#include <iostream>
#include <locale>
#include <string>
using namespace std;

int main(void)
{
  // Set up locale stuff...
  //std::locale::global(std::locale(""));
  //std::wcout.imbue(std::locale());

  wcout.imbue( locale("de_DE") );

  wcout << L"Umlaute: ïüß\n";

  return 0;
}

- -- 
Roger Leigh
                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                Debian GNU/Linux        http://www.debian.org/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFBp8DdVcFcaSW/uEgRAvG5AKCKFQCNPlHd/SXTzzEY0ypkycu9UACgzTsT
CUf7AkRiRumTLO0xliWGqhs=
=jkGv
-----END PGP SIGNATURE-----


reply via email to

[Prev in Thread] Current Thread [Next in Thread]