utf8 中文

#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"Hello.txt");
    wfo.imbue(LocUtf8);
    wfo << L"这是Utf-8编码的文本文件!";
    wfo.close();
  
    wifstream wfi(L"Hello.txt");
    wstring wstr;
    wfi.imbue(LocUtf8);
    wfi >> wstr;
    wcout.imbue(locale(""));
    wcout << wstr << endl;
    system("PAUSE");
}

posted on 2019-06-14 14:32  lydstory  阅读(146)  评论(0编辑  收藏  举报

导航