RSS Forums RSS
Please support our C++ advertiser: Programming Forums

how do I have txt file be read by the compiler?

Join Date: Jul 2005
Posts: 1,395
Reputation: Lerner is just really nice Lerner is just really nice Lerner is just really nice Lerner is just really nice Lerner is just really nice 
Rep Power: 10
Solved Threads: 196
Lerner Lerner is offline Offline
Nearly a Posting Virtuoso

Re: how do I have txt file be read by the compiler?

  #5  
Oct 28th, 2007
Use getline like this

streamName.getline(stringToReadInto, maxNumberOfChars to read, delimiting char);

to read in the first name it would be something like this:

char firstName[11];
myfile.getline(firstName, 10, ' ');

You'll have to run a test program to determine whether it would be 10 or 11 as the second parameter of getline(), because I always forget whether you have to account for the null char or not. I don't think so, but you can find out.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:27 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC