gervaz <ger...@gmail.com> wrote in news:f9eec1c9-5570-461a-bdec-
6dec26dab...@o28g2000yqh.googlegroups.com:
On Jan 30, 1:15?pm, James Kanze <james.ka...@gmail.com> wrote:
On Jan 30, 12:05 pm, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
James Kanze <james.ka...@gmail.com> writes:
There are no standard names for locales
? AFAIK, C90 defines a locale by the name of "C",
? which should also be visible from C++.
And Posix defines "POSIX". ?Neither of which are really useful
for anything.
--
James Kanze
Ok, so I think that I will open my file specifying to use UTF-8
encoding, but how can I do it in C++?
You can open it as a narrow stream and read in as binary UTF-8, or
(maybe) you can open it as a wide stream and get an automatic
translation from UTF-8 to wchar_t. The following example assumes
that you have a file test1.utf containing valid UTF-8 text. It
reads the file in as a wide stream and prints out the numeric
values of all wchar_t characters.
#include <iostream>
#include <fstream>
#include <locale>
#include <string>
int main() {
? ? std::wifstream is;
? ? const std::locale filelocale("en_US.UTF8");
? ? is.imbue(filelocale);
? ? is.open("test1.utf8");
? ? std::wstring s;
? ? while(std::getline(is, s)) {
? ? ? ? for (std::wstring::size_type j=0; j<s.length(); ++j)