•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 375,200 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,227 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 325 | Replies: 3 | Solved
![]() |
•
•
Join Date: Feb 2008
Posts: 433
Reputation:
Rep Power: 1
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 ?
ifstream File("C:\\File1\\");
std::string Line;
while( getline(File, Line, ',') )
{
if ( ? ) // end of file ?
{
}
} •
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,556
Reputation:
Rep Power: 8
Solved Threads: 157
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 2:24 pm.
- On vacation -
Cheers
Cheers
Well do you mean the end of the c++ program or the end of "file.txt" as you have mentioned in the program?
Websitewiz.co.nr
Check out my Old website. Designed it at the age of 12
Check out my Old website. Designed it at the age of 12
•
•
Join Date: Feb 2008
Posts: 433
Reputation:
Rep Power: 1
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- 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 txt file into Hash Table (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



Linear Mode