#include <locale>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ofstream fout("test.txt");
fout.imbue(locale("chs"));
cout.imbue(locale("C"));
cout.rdbuf(fout.rdbuf());
cout << "中文"; // Which locale will apply to here? "C" or "chs"?
}
The question is commented in the code.
From http://www.cplusplus.com/reference/ios/ios/imbue/
Also, see http://stdcxx.apache.org/doc/stdlibug/27-4.html
In your case, it would use the “C” numeric locale and the “chs” character locale.