#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
// 必须先设置这个,获取全局的这个locale值
locale::global(locale("zh_CN.UTF-8"));
// 或者linux的LANG变量已经是zh_CN.UTF-8,也可以用下面的
// locale::global(locale(""));
// 也可以下面这个
// locale::global(locale("en_US.UTF-8"));
locale l("");
wcout.imbue(l);
wstring s = L"热大大";
wcout << s << endl;
// 写文件, 用宽输出流
wofstream f("assess.log");
f.imbue(l);
f << L"热大大sada\n";
f << s << '\n';
f.close();
//读取文件
wifstream fr("assess.log");
wstring ws;
// while (getline(fr, ws))
// {
// wcout << ws << endl;
// }
while (fr >> ws)
{
wcout << ws << endl;
}
fr.close();
return 0;
}
C++输出中文
最新推荐文章于 2024-03-22 22:02:37 发布