从文件 C++ 读取总是无法读取 [英] Read from file c++ always can't read

查看:119
本文介绍了从文件 C++ 读取总是无法读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ifstream myfile;
myfile.open("FileTest");

string line;

if(myfile.is_open())
{
  cout<<"Reading from file...";
  getline(myfile,line);
}

if(myfile.fail())
{
    cout<<"Unable to open file"<<endl;
}

myfile.close();

推荐答案

C++ 尝试打开当前目录中具有确切名称 FileTest 的文件.检查文件是否在当前目录中?也许你拼错了名字?也许你忘了写FileTest.txt?您正在使用 ifstream,如果您尝试打开的文件不存在或已损坏,它将失败.

C++ tries to open the file in the current directory with the exact name FileTest. Check to see if the file is in the current directory? Maybe you spelled the name incorrectly? Maybe you forgot to write FileTest.txt? You are using ifstream, which will fail if the file you're trying to open does not exist or is corrupted.

这篇关于从文件 C++ 读取总是无法读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆