vc++中如何将wchar_t宽字符写入文本文件

来源:互联网 发布:厦门美工培训班 编辑:程序博客网 时间:2024/06/06 09:40
如果想保存wchar_t的数据,可以用:    wchar_t * gg;    gg=L"aaaa如何666";    FILE* file;    file = fopen("a.txt", "a");    fwrite(gg, sizeof(wchar_t), wcslen(gg), file);    fclose(file);只是这样保存下来的是unicode数据(比如'a'保存成 0x61 0x00)).另外一个办法是先将wchar_t型数据转成char型的(用WideCharToMultiByte函数),再保存。比如:    wchar_t * gg;    gg=L"aaaa如何666";    char hh[256];    WideCharToMultiByte(CP_ACP, 0, gg, wcslen(gg) + 1, hh, 256, NULL, NULL);    wfstream ff;    ff.open("a.txt",ios::app|ios::out);    ff<<"aa好啊"<<hh<<"\n";    ff.close();