我们如何同时将WCHAR和CHAR写入wofstream?
wofstream << L"汉字" << "汉字"
这里是要测试的东西。我只能“ wofstream <
#include <iostream>
#include <fstream>
#include <locale>
int main() {
std::wofstream wof2;
wof2.open(L"2.txt", std::wofstream::app);
wof2 << "\nCHAR 汉";
wof2.flush();
wof2 << L"\nWCHAR 汉";
wof2.close();
const char * tmp = setlocale(LC_ALL, "");
std::cout << tmp << std::endl;
std::locale::global(std::locale(""));
wof2.open(L"2.txt", std::wofstream::app);
wof2.imbue(std::locale());
wof2 << L"\nWCHAR after imbue";
wof2.flush();
wof2 << L"\nWCHAR 汉";
wof2.flush();
wof2 << "\nCHAR汉";
wof2.flush();
return 0;
}
我们可以在控制台上看到
Chinese (Simplified)_China.936
但是在2.txt中,我看到了
CHAR 汉
WCHAR
WCHAR after imbue
WCHAR 汉
CHAR