运行之后跳出来一下,就看不到结果了
比如这个是怎么加的呢?? 我试了所有的方法都不能解决。//。。
#include<string>
#include<fstream>
#include<iostream>
#include <stdio.h>
using namespace std;
int main()
{
fstream tfile("readme.txt",ios::out|ios::in);
if(tfile.fail())
{
cout<<"Can't open the file"<<endl;
exit(0);
}
tfile<<"hello"<<endl;
string line;
///////////添加就可以看到,文件已经失败了!
if(tfile.fail())
{
cout<<"Can't open the file"<<endl;
tfile.close(); //关闭然后再打开
tfile.open("readme.txt");
}
tfile.seekg(0,ios::beg);
while(getline(tfile,line))
{
cout<<line<<endl;//一定要有endl
}
return 0;