help-gplusplus
[Top][All Lists]
Advanced

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

iostreams and code conversion


From: Jens Theisen
Subject: iostreams and code conversion
Date: 09 Oct 2006 01:57:56 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Hello,

I experimented with the iostreams locale support and am puzzled with
the results. It might be off-topic to post here, but I'm using gcc
(with glibc locale backend) as the platform and am unsure if it's a
platform specific problem or not.

I tried

  wcout.imbue( locale("") );

  wcout << wchar_t(0xe4); // is the unicode codepoint for `ä'

using a en_GB.UTF-8 locale, but the output isn't converted to utf8
(not sure what it actually is that comes out). The conversion facet is
correctly installed, and indeed

  wofstream os("test.txt");

  os.imbue( locale("") );

  os << wchar_t(0xe4);

does what one would expect. I had a quick scan through the sources and
noticed that the only place where libstdc++ appear to honour this
facet are the filebufs - which appears to me as the least sensible
place.

The standard indeed mentions special code conversion with this facet
for fstreams, and appears not to for other streams (in particular, I
can't find anything about cout/cin/cerr in this regard).

However, it seems very reasonable to have them at least for the
stdio_sync_filebuf as well, as one would rather want the above code
for output "just work", and the after all the following works in C:

  setlocale(LC_ALL, "");

  char const* narrow = "\xc3\xa4";
  wchar_t const* wide = L"\xe4";

  printf("printf narrow: %s\n", narrow);
  printf("printf wide:  %ls\n", wide);

So it should in C++ with iostreams, shouldn't it?

Does someone know more?

Thanks for any information!

-- 
Gruß, Jens



reply via email to

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