Yandong_Ji 2018-05-21 22:52 采纳率: 66.7%
浏览 547
已采纳

输入流相关,读取相关文件错误

#include
#include
using namespace std;
int main()
{
char str[12];
ifstream ifile;
ifile.open("test", ios::out);
if (!ifile)
{
cerr << "Can't open test file." << endl;
system("pause");
return 0;
}
ifile >> str;
cout << str << endl;
ifile.close();
system("pause");
return 1;
}


图片说明
图片说明
为什么总是出现这样的情况.......那个test文件真的不用写后缀吗?

  • 写回答

8条回答 默认 最新

  • mefish 2018-05-22 01:11
    关注

    需要写后缀。"test.txt", 如果test.txt不在程序所在目录或不在工作目录下,还需要完整路径

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

报告相同问题?