This is the mail archive of the libstdc++@sources.redhat.com 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]

Re: character encoding (locale)



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");

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