如何在C++

发布于 2025-02-11 00:57:25 字数 339 浏览 1 评论 0原文

我正在学习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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白首有我共你 2025-02-18 00:57:25

如果仅使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文