This is the mail archive of the
libstdc++@sources.redhat.com
mailing list for the libstdc++ project.
Re: character encoding (locale)
- To: Jan Schukat <selberschuld at gmx dot de>
- Subject: Re: character encoding (locale)
- From: Benjamin Kosnik <bkoz at redhat dot com>
- Date: Tue, 12 Dec 2000 09:29:24 -0800 (PST)
- cc: libstdc++ at sourceware dot cygnus dot com
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");