明明文件的路径是正确的,就是打不开文件,各位有发现什么问题吗?
#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;
}
“ (这里有一个看不见的神秘字符)test.txt”
你把 "test.txt"整个删掉,再重新敲一遍,再试试。
文件在c盘吗,再c盘可能需要管理员权限,两种方法尝试一下,一是把文件放在非系统盘,二是关闭编译器,然后以管理员身份重新启动