| | |
End Of File (ifstream)
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
If I am reading a .txt file with ifstream, what is the syntax to recognice if I have reached the end of file. From what I have heard somewhere before, I think it has with eof to do ?
C++ Syntax (Toggle Plain Text)
ifstream File("C:\\File1\\"); std::string Line; while( getline(File, Line, ',') ) { if ( ? ) // end of file ? { } }
cpp Syntax (Toggle Plain Text)
ifstream File("C:\\File1\\"); std::string Line; while( getline(File, Line, ',') ) { // do stuff } // the end of the file is here
It's as simple as that

And I wouldn't use 'File' as a name because it looks to much like : FILE. Something like 'infile' would be better IMO.
Last edited by niek_e; May 10th, 2008 at 3:24 pm.
Well do you mean the end of the c++ program or the end of "file.txt" as you have mentioned in the program?
•
•
Join Date: Feb 2008
Posts: 517
Reputation:
Solved Threads: 1
Thanks... you are right, that solved the problem 
I will think about not using File too.

I will think about not using File too.
•
•
•
•
cpp Syntax (Toggle Plain Text)
ifstream File("C:\\File1\\"); std::string Line; while( getline(File, Line, ',') ) { // do stuff } // the end of the file is here
It's as simple as that
And I wouldn't use 'File' as a name because it looks to much like : FILE. Something like 'infile' would be better IMO.
![]() |
Similar Threads
- Reading txt file into Hash Table (C++)
- How to find End of file (C++)
- Getting all data from an input and output file (C++)
- While loop not ending when reading from file (C++)
- Help with comparing user input to a text file! (C++)
- A question about file streaming (C++)
- C++: ifstream file pointer not getting reset (C++)
- reading from file into array (C++)
- Help Reading Info in Text File Into an Array (C++)
Other Threads in the C++ Forum
- Previous Thread: importance of dllexport location in program
- Next Thread: very short code question plz help
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






