在vs2008中使用unicode编译如何使用wofstream将多个语言字符输出到C++中的文件?
我可以用C代码来做,没问题。
FILE *out;
if( (out = _wfopen( L"test.txt", L"wb" )) != NULL )
{
fwprintf(out,L"test\r\n");
fwprintf(out,L"наказание\r\n");
fwprintf(out,L"ウェブ全体から検索\r\n");
}当我打开文件时,一切都是正确的,但是使用下面的C++程序,我得到的只是第一行,并且我已经尝试了locale::global(locale(""));,结果是一样的。
wofstream MyOutputStream(L"test.txt");
if(!MyOutputStream)
{
AfxMessageBox(L"Error opening file");
return;
}
MyOutputStream << L"test\r\n";
MyOutputStream << L"наказание\r\n";
MyOutputStream << L"ウェブ全体から検索\r\n";
MyOutputStream.close();我试着插入这个,结果是一样的:-
std::locale mylocale("");
MyOutputStream.imbue(mylocale);发布于 2015-06-18 04:38:37
已经解决了..。这就是:
wofstream MyOutputStream(L"c:\\test2.txt", ios_base::binary);
wchar_t buffer1[128];
MyOutputStream.rdbuf()->pubsetbuf(buffer1, 128);
MyOutputStream.put(0xFEFF);
MyOutputStream << L"test\r\n";
MyOutputStream << L"наказание\r\n";
MyOutputStream << L"ウェブ全体から検索\r\n";发布于 2015-06-19 00:55:25
最后可以工作的代码是:
wofstream MyOutputStream(L"c:\\test2.txt", ios_base::binary);
if(!MyOutputStream)
{
AfxMessageBox(L"Error opening file");
return;
}
wchar_t buffer1[128];
MyOutputStream.rdbuf()->pubsetbuf(buffer1, 128);
MyOutputStream << L"test\r\n";
MyOutputStream << L"наказание\r\n";
MyOutputStream << L"ウェブ全体から検索\r\n";
MyOutputStream.close();https://stackoverflow.com/questions/30900775
复制相似问题