我std::wofstream
用来在文本文件中写入字符。我的字符可以有来自非常不同语言的字符(英文到中文)。我想将我的打印vector<wstring>
到该文件中。如果我的矢量只包含英文字符,我可以毫无问题地打印它们。但是如果我写中文字符,我的文件仍然是空的。
我浏览了stackoverflow,所有答案基本上都说使用库中的函数:
#include <codecvt>
我不能包含那个库,因为我在 5.11 版中使用的是 Dev-C++。我做到了:#define UNICODE
在我所有的头文件中。我想这个问题有一个非常简单的解决方案。如果有人可以帮助我,那就太好了。
我的代码:
#define UNICODE
#include <string>
#include <fstream>
using namespace std;
int main()
{
string Path = "D:\\Users\\\t\\Desktop\\korrigiert_RotCommon_zh_check_error.log";
wofstream Out;
wstring eng = L"hello";
wstring chi = L"程序";
Out.open(Path, ios::out);
//works.
Out << eng;
//fails
Out << chi;
Out.close();
return 0;
}
亲切的问候