I read a bunch of articles and forums discussing this problem, all solutions seem too complicated for such a simple task.
Here is a sample code directly from cplusplus.com:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
It works fine as long as example.txt only has ASCII characters. Things become messy if I try to add, say, something in Russian.
On GNU / Linux, it is as simple as saving a file as UTF-8.
On Windows, this does not work. Converting a file to UCS-2 Little Endian (which Windows apparently uses by default) and wchar_t does not do all the changes in its colleagues either.
Is there any “right” way to do this without doing all kinds of magic coding transforms?