#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
ifstream ifs;
ifs.open("file.txt",ios::in);//读文件
if(!ifs.is_open())
{
perror("file");
return 0;
}
char buf[1024]="";
while(ifs>>buf)
{
cout << buf;
}
cout << endl;
ifs.close();
return 0;
}
我的CMakeLists.txt文件和目录结构,我将代码中的file.txt改为绝对路径也会报找不到文件的错误,但是用g++直接编译就能读取file.txt,不知道为什么,有人能指教以下吗?