character encoding (locale)

Benjamin Kosnik bkoz@redhat.com
Tue Dec 12 09:29:00 GMT 2000


I suggest "Standard C++ IOStreams and Locales" by Angelika Langer and 
Klaus Kreft, for more info. This is a great book.

> I watched the sources and your documentation quite a while. As I still have
> no copy of the standard (don't ask) there is one question I have.
> Can a program in any way determined by the standard get the character
> encoding of a file in a just opened stream. I don't mean the locales in ios or
> the connected streambuf. I mean how do you get the encoding of a plain text
> file.

I suspect you mean "deduce" the encoding. And the answer is that we can 
use the locale set by the "C" library as the C++ default. So, if you set 
the C locale correctly, the C++ locale should default to being the 
correct thing.

You can always set the locale explictly, before you read in a file, with 
the imbue member function.

If you have to deal with specific encodings, you might want to look 
at the documention under 22_locale for codecvt. If you use 
__enc_traits specializations you can specify specific encodings.

-benjamin


> ifstream in("text.txt");
> 
> or
> 
> wifstream in("text.txt");


More information about the Libstdc++ mailing list