这是我在实现方法之前用来测试方法的主文件。我正在尝试获取目录中所有文件的列表,将它们写入 txt 文件(直到这里都可以正常工作),然后从该文本文件中读取文件名。
using namespace std;
string sysCall = "", location = "~/Documents/filenames.txt";
string temp = "";
sysCall = "ls / > "+location;
system(sysCall.c_str());
ifstream allfiles(location.c_str());
allfiles.good();
getline(allfiles, temp);
cout<<temp<<endl; //At this point, the value of temp is equal to ""
return -1;
程序运行后,没有任何文字输出。从我在其他人的问题中读到的内容来看,这应该有效(但显然无效)。我在这里做错了什么?
编辑: allfiles.good() 返回false,但我不明白为什么它会返回...