#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"?
}
该问题在代码中进行了注释。