#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
char ch;
ifstream fin("text.txt");
if(!fin) {
cout << "Cannot open file.\n";
return 1;
}
do {
fin.get(ch);
if(!fin.eof() && (fin.fail() || fin.bad())) {
cout << "Input Error\n";
fin.close();
return 1;
}
if(!fin.eof()) cout << ch;
} while(!fin.eof());
fin.clear();
fin.close();
if(!fin.good()) {
cout << "Error closing file.";
return 1;
}
return 0;
}
Use eof() to read and display a text file.
最新推荐文章于 2024-03-24 20:34:08 发布