ios eof() function in C++ with Examples Last Updated : 12 Jul, 2025 Comments Improve Suggest changes 4 Likes Like Report 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 eofbit set. Syntax: 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. Time Complexity: O(1) Auxiliary Space: O(1) Example 1: CPP // C++ code to demonstrate // the working of eof() function #include <bits/stdc++.h> using namespace std; int main() { // Stream stringstream ss; // Using eof() function bool isEOF = ss.eof(); // print result cout << "is stream eof: " << isEOF << endl; return 0; } Output:is stream eof: 0 Example 2: CPP // C++ code to demonstrate // the working of eof() function #include <bits/stdc++.h> using namespace std; int main() { // Stream stringstream ss; ss.clear(ss.eofbit); // Using eof() function bool isEOF = ss.eof(); // print result cout << "is stream eof: " << isEOF << endl; return 0; } Output:is stream eof: 1 Reference: hhttps://cplusplus.com/reference/ios/ios/eof/ Create Quiz Comment G guptayashgupta53 Follow 4 Improve G guptayashgupta53 Follow 4 Improve Article Tags : Misc C++ CPP-Functions cpp-ios Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like