gpt4 book ai didi

c++ - 使用fopen创建新文件时如何设置FILE*对象编码格式?

转载 作者:行者123 更新时间:2023-11-28 04:25:11 27 4
gpt4 key购买 nike

我在我的mac上开发了一个macos应用程序,有一些信息需要写到我的log.txt文件中,这些信息包含中英文字符串,所以我使用fopen方法创建log.txt :

 FILE * m_pFile = fopen(filename, "a+, ccs=UTF-8");

但是当打开log.txt时,它显示中文字符串中的乱码:

原始中文字符串为'当前启动次数是-----',

log.txt中的字符串是'ÂΩìÂâçÂêØÂä®Ê¨°Êï∞ÊòØ---',

如何正确打印log.txt文件中的中英文字符串,万分感谢!

最佳答案

可能重复:C++ writing UTF-8 on Linux

引用:

the extensions done on Windows do not work on Linux, OS-X, Android, iOS and everywhere else. The Microsoft just makes those extensions to achieve that you write incompatible code with other platforms.

Convert your wide string to byte string that contains UTF-8, then write the bytes to file like usual.

关于c++ - 使用fopen创建新文件时如何设置FILE*对象编码格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54491211/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com