编写一个文本文件读取程序,打开
test.txt
文件,读取所有内容并显示在屏
幕上。
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file("text.txt",ios::in);
if(!file.fail())
{
while(!file.eof())
{
char buf[128];
file.getline(buf,128);
if(file.tellg()>0)
cout<<buf<<endl;
}
}
else
cout<<"can not open"<<endl;
file.close();
return 0;
}