克莱恩莫雷蒂 2021-09-05 15:46 采纳率: 33.3%
浏览 30
已结题

C++读取txt文件的问题

明明文件的路径是正确的,就是打不开文件,各位有发现什么问题吗?

#include <iostream>
#include<fstream>
#include<string>
using namespace std;

void test01()
{
    ifstream ifs;
    ifs.open("‪test.txt", ios::in);
    if (!ifs.is_open()) { cout << "文件打开失败" << endl; return; }
    string str;
    while (getline(ifs, str))
    {
        cout << str << endl;
    }
    ifs.close();
}

int main() {

    test01();

    system("pause");

    return 0;
}

img

  • 写回答

2条回答 默认 最新

  • 赵4老师 2021-09-05 16:17
    关注

    “ (这里有一个看不见的神秘字符)test.txt”
    你把 "test.txt"整个删掉,再重新敲一遍,再试试。

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

报告相同问题?

问题事件

  • 系统已结题 9月13日
  • 已采纳回答 9月5日
  • 创建了问题 9月5日