#include <fstream>
//如果没有imbue()的调用,写入,读取,显示都不正常
void Write(std::wstring& data)
{
std::wofstream f;
f.imbue(std::locale("chs"));
f.open("test.txt", std::ios::out);
f.seekp(0, std::ios::beg);
f << data;
f.close();
f.clear();
}
void Read()
{
wchar_t data[32] = { 0 };
std::wifstream f;
f.imbue(std::locale("chs"));
f.open("test.txt", std::ios::in);
f >> data;
std::wcout.imbue(std::locale("chs"));
std::wcout << data << std::endl;
f.close();
f.clear();
}
int main()
{
std::wstring str = L"你好,世界";
//
Write(str);
Read();
return 0;
}