End Of File (ifstream)

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

End Of File (ifstream)

 
0
  #1
May 10th, 2008
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 ?

  1. ifstream File("C:\\File1\\");
  2. std::string Line;
  3.  
  4. while( getline(File, Line, ',') )
  5. {
  6.  
  7. if ( ? ) // end of file ?
  8.  
  9. {
  10.  
  11. }
  12. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,839
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 298
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Roasting Maven

Re: End Of File (ifstream)

 
0
  #2
May 10th, 2008
  1. ifstream File("C:\\File1\\");
  2. std::string Line;
  3.  
  4. while( getline(File, Line, ',') )
  5. {
  6. // do stuff
  7. }
  8. // 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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 672
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 99
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: End Of File (ifstream)

 
0
  #3
May 10th, 2008
Well do you mean the end of the c++ program or the end of "file.txt" as you have mentioned in the program?
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 517
Reputation: Jennifer84 is an unknown quantity at this point 
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro

Re: End Of File (ifstream)

 
0
  #4
May 10th, 2008
Thanks... you are right, that solved the problem
I will think about not using File too.

Originally Posted by niek_e View Post
  1. ifstream File("C:\\File1\\");
  2. std::string Line;
  3.  
  4. while( getline(File, Line, ',') )
  5. {
  6. // do stuff
  7. }
  8. // 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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC