Hello guys,
I got the eofbit and failbit when we readed the file end.
My question is if How can I clear the eof and fail stat whith out fstream::clear.
Is the close doesn't work?
see my code as below:
ifstream in("sample");
if (in.fail())
error(); //open successful
int i;
while (in >> i) ; //I got the eof and fail after while
in.close();
in.clear();// I closed the file why I need clear
in.open("sample");
if (in.fail())
error(); //if I don't use clear then open failed.
Is the close doesn't work in C++ we should use clear too?WHY C used fclose(in) only and works fine?
Hi Mattia,
Thank you.
Please see the full code:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{int aver,bzc,m,sum=0;
int count=0;
ifstream fin;