首先,vs2017的编码格式如下:

vs使用ifstream从txt文件中读取中文输出乱码的解决方案

 

 代码如下:

#include <iostream>
#include<string>
#include<fstream>
using namespace std;
int cnt = 0;
int main()
{

    string s;
    ifstream in("input.txt");
    if (in)
    {
        while (in)
        {
            in >> s;
            cout << s << endl;
            cnt++;
            if (cnt >= 11)break;
        }
    }
    return 0;
}

怎么查看input.txt这个文件的编码格式呢?

  打开txt文件 ,点击左上角文件,另存为,即可在最下面看到一开始的txt

文件的编码格式也为UTF-8格式的。

  这个时候我们把txt文件选择

vs使用ifstream从txt文件中读取中文输出乱码的解决方案

 

 

  这个格式保存就能完美地解决这个问题了。

相关文章:

  • 2021-06-29
  • 2021-12-30
  • 2021-12-03
  • 2021-06-13
  • 2022-12-23
  • 2021-08-13
  • 2022-12-23
  • 2021-09-14
猜你喜欢
  • 2021-05-10
  • 2021-06-05
  • 2022-12-23
  • 2021-07-07
  • 2021-10-30
  • 2022-12-23
  • 2021-05-25
相关资源
相似解决方案