类型什么的都用前缀w宽字符,主要是是第九行:保存个类型变量,和12行设置out编码还有19行设置in编码
#include <iostream>
#include <codecvt>
#include <fstream>
#include <string>
int main(void)
{
using namespace std;
auto LocUtf8 = locale(locale(""), new codecvt_utf8<wchar_t>);
// 输出文件
wofstream wfo(L"F:\\a_ligong\\HYL38.txt");
wfo.imbue(LocUtf8);
wfo << L"这是Utf-8编码的文本文件!";
wfo.close();
// 输入文件
wifstream wfi(L"F:\\a_ligong\\HYL38.txt");
wstring wstr;
wfi.imbue(LocUtf8);
wcout.imbue(locale(""));
while (!wfi.eof()) {
getline(wfi, wstr);
wcout << wstr;
}
system("PAUSE");
}
非原创!!!转载只是找不到来源了,以后找到会补上