代码搬运工@@ 2018-01-18 06:00 采纳率: 50%
浏览 5288
已采纳

vs2015 C++读取文件输出内容,总是显示乱码

#include
#include
#include
#include
#include
using namespace std;
int main()
{
ifstream sfile("1.txt");
if (!sfile)
{
cerr << "无法打开文件" << endl;
system("pause");
return -1;
}

string line;
vector<string> word;
while (getline(sfile, line))
{
    word.push_back(line);
}
sfile.close();
//for (auto it :word)
vector<string>::const_iterator it = word.begin();
while (it != word.end())
{
    istringstream line_str(*it);
    string words;
    while (line_str >> words)
        cout << words << " ";
    cout << endl;
    ++it;
}
system("pause");
return 0;

}
图片说明

  • 写回答

15条回答 默认 最新

  • 浩子乄 2018-01-18 06:06
    关注

    你将文件编码修改一下

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(14条)

报告相同问题?