我无法弄清楚为什么我的代码无法打开和读取文件.我错过了什么?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main (int argc, char * const argv[])
{
string line;
ifstream myfile ("input_file_1.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
getline (myfile,line);
cout << line << endl;
}
}
else
{
cout << "Was unable to open the file" << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
文件"input_file_1.txt"与我的.cpp文件在同一目录中,并且具有读取权限.我甚至给了它777权限,我无法阅读它.
谁能告诉我我做错了什么?我真的想不出来......
| 归档时间: |
|
| 查看次数: |
3657 次 |
| 最近记录: |