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.