老实说,我只是没有在C++标准库中得到以下设计决定.将宽字符写入文件时,将wofstream转换wchar_t为char字符:
#include <fstream>
#include <string>
int main()
{
using namespace std;
wstring someString = L"Hello StackOverflow!";
wofstream file(L"Test.txt");
file << someString; // the output file will consist of ASCII characters!
}
Run Code Online (Sandbox Code Playgroud)
我知道这与标准有关codecvt.还有codecvt的utf8在Boost.此外,还有一个codecvt用于utf16由马丁·约克在这里SO.现在的问题是,为什么在standard codecvt转换宽字符?为什么不按原样写人物!
另外,我们是否会unicode streams使用C++ 0x或者我在这里遗漏了什么?