【问题标题】:File reading and writing in cp866 encoding in C++C++中cp866编码的文件读写
【发布时间】:2011-11-05 19:55:47
【问题描述】:

如何在 C++ 中正确读写 cp866 编码的文本文件?

UPD:我找到了一种写入文件的方法

wofstream rstrm(fileName);
rstrm.imbue(locale("rus_rus.866"));
rstrm << text_in_cyrillic.c_str();
rstrm.close();

现在我怎样才能以类似的方式读取文件?我需要将文件内容读取到 tstring 对象。

【问题讨论】:

  • 为什么需要?使用 UTF-8 怎么样? std::string s; file &gt;&gt; s; 也可以,但可能不是你想要的。
  • @ybungalobill 不幸的是,这不是我的情况。

标签: c++ file winapi encoding dos


【解决方案1】:

使用WideCharToMultiByte并告诉它cp866,并写出结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-22
    • 2011-05-20
    • 2018-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多