C++ IOS :: eof() function














































C++ IOS :: eof() function



 DESCRIPTION: 

The eof() method of ios class in C++ is used to check if the stream is has raised any EOF (End Of File) error. It  means that this function will check if this stream has its eof bit set.

  Declaration:  

  bool eof( ) const;

  Parameters:    

  This method does not accept any parameter.

  Return Value:

  This method returns true if the stream has eofbit set, else false.

  Program:

#include <sstream> 

#include <iostream>


int main() {


std::stringstream ss( );


    bool isEOF = ss.eof();


    std::cout << "is stream eof : " << isEOF << '\n';

}


  Output:
is stream eof : 0
   
       Program:

 #include <iostream>
#include <sstream>
using namespace std;
int main()
{
    std::stringstream ss( );
  ss.clear(ss.eofbit);
    bool isEOF = ss.eof();
   
 
    cout << "is stream of : " << isEOF << endl
        
}

Output:

is stream eof : 1

In the above program we used clear( ) function to empty the string and hence the eof( ) function gives the output as 1(true).


ur Code Here...

Comments