std::wstring s = L"输入法."; // random characters pulled from baidu.cn
Using
std::codecvt_utf8
locale
或boost
下面是我使用的代码:
std::wofstream out(destination.wstring(), std::ios_base::out | std::ios_base::app);
const std::locale utf8_locale = std::locale(std::locale(), new boost::locale::utf8_codecvt<wchar_t>());
out.imbue(utf8_locale);
// Verify that the file opened correctly
out << s << std::endl;