Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 输出C+中的多字节字符串+;_C++_Multibyte_Wofstream - Fatal编程技术网

C++ 输出C+中的多字节字符串+;

C++ 输出C+中的多字节字符串+;,c++,multibyte,wofstream,C++,Multibyte,Wofstream,我对多字节字符字符串有问题。我将我的问题简化如下: std::wstring str = L"multıbyte test string"; std::wofstream f; f.open("F:\\dump.txt"); f << str; f.close(); std::wstring str=L“多字节测试字符串”; std::wofsf; f、 打开(“f:\\dump.txt”); fwofstream使用当前区域设置写出数据。默认区域设置可能不支持多字节字符 见问题:

我对多字节字符字符串有问题。我将我的问题简化如下:

std::wstring str = L"multıbyte test string";
std::wofstream f;
f.open("F:\\dump.txt");
f << str;
f.close();
std::wstring str=L“多字节测试字符串”;
std::wofsf;
f、 打开(“f:\\dump.txt”);

f
wofstream
使用当前区域设置写出数据。默认区域设置可能不支持多字节字符

见问题:

您可以通过以下方式使其输出完整字符串:

std::locale::global(std::locale(""));
但是,在编写之前,您不会在windows上获得unicode字符,因为它不支持UTF-8本地语言环境


要做到这一点,您应该使用
WideCharToMultiByte
将其转换为std::string,并使用stream
的常规
将其写出。您必须向输出流注入一些区域设置,以获得一些合理的
codevt
方面来进行
wchar\u t
char
转换。如果您有支持C++11的编译器或Visual Studio 2010及更高版本,则可以使用UTF-8 facet():

f.imbue(
std::locale(//使用从
std::locale(),//全局语言环境
//和编解码器vt_utf8方面
新标准::编解码器VT_utf8);

还有。

一些问题:你的操作系统说转储文件有多大?你是如何检查转储文件的内容的?multıbyte中的字符“ı”会导致任何问题吗?
f.imbue(
    std::locale (         // using std::locale constructed from
        std::locale (),   // global locale
                          // and codecvt_utf8 facet
            new std::codecvt_utf8<char, 0x10FFFF,
                static_cast<std::codecvt_mode>(std::consume_header
                    | std::little_endian)>);