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++ 将UTF-8/16写入文件,什么';在不推荐使用codevt_utf16之后,它是codevt_utf16的替代方案吗?_C++_File_Unicode - Fatal编程技术网

C++ 将UTF-8/16写入文件,什么';在不推荐使用codevt_utf16之后,它是codevt_utf16的替代方案吗?

C++ 将UTF-8/16写入文件,什么';在不推荐使用codevt_utf16之后,它是codevt_utf16的替代方案吗?,c++,file,unicode,C++,File,Unicode,正如我们所知,在将UTF-8/16写入文件时,您应该使用std::codecvt\u utf16或std::codecvt\u utf8\u utf16,如下所示: std::wofstream WFile(“file.txt”); 如果(!WFile.is_open())返回false; imbue(std::locale(WFile.getloc(),新std::codevt_utf16()); 文件相关:。从“用户应该使用专用的文本处理库”开始。您的代码与UTF8无关。顺便说一下,UTF8

正如我们所知,在将UTF-8/16写入文件时,您应该使用
std::codecvt\u utf16
std::codecvt\u utf8\u utf16
,如下所示:

std::wofstream WFile(“file.txt”);
如果(!WFile.is_open())返回false;
imbue(std::locale(WFile.getloc(),新std::codevt_utf16());

文件相关:。从“用户应该使用专用的文本处理库”开始。您的代码与UTF8无关。顺便说一下,UTF8优于UTF16。Windows程序也更喜欢使用UTF8来保存文件和联网。只需将UTF16转换为UTF8,并使用
std::ofstream
@BarmakShemirani保存它:该代码只是一个示例,但我的问题通常是关于使用
std::codevt_
是UTF-16还是UTF-8。UTF8不需要
codevt_
。只需使用流的std::of(“file.txt”)