User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Feb 2008
Posts: 433
Reputation: Jennifer84 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro in Training

End Of File (ifstream)

  #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 ?

ifstream File("C:\\File1\\");
std::string Line;

while( getline(File, Line, ',') )
{

        if (         ?           )   // end of file ?

        {
   
        }            
} 
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,556
Reputation: niek_e is a jewel in the rough niek_e is a jewel in the rough niek_e is a jewel in the rough niek_e is a jewel in the rough 
Rep Power: 8
Solved Threads: 157
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Virtuoso

Re: End Of File (ifstream)

  #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 2:24 pm.
- On vacation -
Cheers
Reply With Quote  
Join Date: Mar 2008
Posts: 137
Reputation: Sky Diploma is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 20
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Junior Poster

Re: End Of File (ifstream)

  #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?
Websitewiz.co.nr
Check out my Old website. Designed it at the age of 12
Reply With Quote  
Join Date: Feb 2008
Posts: 433
Reputation: Jennifer84 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
Jennifer84 Jennifer84 is offline Offline
Posting Pro in Training

Re: End Of File (ifstream)

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 2:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC