如何在C++
我正在学习C ++,并且需要编写在ISO-8859-1或WINCP-1252中编码的CSV文件。
我已经尝试了以下代码段来设置将使用1252 CodePage编码的语言环境,但是当我在Notepad.exe中打开输出文件时,编码将显示为UTF-8。
std::ofstream ofs;
ofs.imbue(std::locale("English_United States.1252"));
ofs.open("file.txt");
ofs << 78123.456 << std::endl;
I am learning C++ and I have a requirement to write a CSV file encoded in ISO-8859-1 or WinCP-1252.
I've tried the following code snippet to set a locale that will use 1252 codepage encoding, but when I open the output file in Notepad.exe, the encoding is displayed as UTF-8.
std::ofstream ofs;
ofs.imbue(std::locale("English_United States.1252"));
ofs.open("file.txt");
ofs << 78123.456 << std::endl;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果仅使用ASCII代码0..127的字符,则不应关心文件编码。 UTF-8是默认的记事本编码,8位多键。记事本不是确定文件编码的工具。换句话说,具有ASCII代码的字符0..127可以被认为是任何8位ISO或多键编码。
If you use only chars with ASCII codes 0..127, you should not care of a file encoding. UTF-8 is a default Notepad encoding, 8-bit multibyte. Notepad is not a tool for determining a file encoding. In other words, chars with ASCII codes 0..127 can be considered to be any 8-bit ISO or multibyte encoding.