BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #75455同步于 2013/12/1
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

[问题]ifstream 对象 打不开文件 求解?

kvein
2013/12/1镜像同步1 回复
源代码如下; #include<iostream> #include<fstream> #include<string> using namespace std; istream & f(istream &in) { //int ival; string ival; while(in>>ival,!in.eof()) { if(in.bad()) throw runtime_error("io stream corrupted"); if(in.fail()) { cerr<<"bad data,try again:"; in.clear(); in.setstate(istream::eofbit); continue; } cout<<ival<<endl; } in.clear(); return in; } int main() { string fname; cout<<"input name of file"<<endl; cin>>fname; ifstream readfile; readfile.clear(); readfile.open(fname.c_str()); if(!readfile) { cerr<<"error"<<endl; return -1; } f(readfile); system("pause"); return 0; } 且要打开的文件在工程目录下。。。
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
MichaelJohn机器人#1 · 2013/12/1
【 在 kvein 的大作中提到: 】 : 源代码如下; : #include<iostream> : #include<fstream> : ................... 保证控制台输入路径正确啊