【问题标题】:why are special characters read false from file为什么特殊字符从文件中读取为假
【发布时间】:2010-02-12 22:16:01
【问题描述】:

您好,我的程序将一些设置(主要是字符串)保存到一个文本文件中,以便稍后检索它们,但是唉!特殊字符回来无法识别!

saveSettings 将字符串一一保存...

void email::saveSettings(string filename){
    ofstream savefile(filename.c_str(),ios::out | ios::trunc);
    email settingsemail(this);
    savefile <<mailprog<<endl;
    ...

loadSettings 检索它们...

bool loadSettings(string filename){
    char chtemp[255];
    ifstream savefile(filename.c_str(), ios::in);
    if (savefile.is_open()){
    savefile.getline(chtemp,255);
    mailprog=chtemp;
    savefile.getline(chtemp,255);
    smtp=chtemp;
    ...

一些文本包含字母“é”,读回为“8”

感谢您的任何提示

【问题讨论】:

    标签: c++ special-characters ifstream ofstream


    【解决方案1】:

    也许您应该考虑使用 Unicode 版本的 getline :)

    更多信息请见this article

    【讨论】:

      【解决方案2】:

      尝试将ios::binary 添加到您的流构造函数标志中。

      【讨论】:

        猜你喜欢
        • 2021-12-08
        • 1970-01-01
        • 1970-01-01
        • 2020-05-03
        • 2015-01-28
        • 2017-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多