C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Ignoring blank lines for file input Posted by atria on 25 May 2007 at 7:33 AM
Hi, i am trying to write a program that:
1) read an ascii formatted file into memory
2) modify the file slightly without changing the format and number of characters
3) output the changed data

heres the code:
ifstream infile("C:\\data.txt");
vector<xdcc> xdcc_array;
while(!infile.eof()) {
  xdcc xdcc_read;
  infile >> xdcc_read.name >> xdcc_read.packno >> xdcc_read.status;
  xdcc_array.push_back(xdcc_read);
}


heres the format of the input file:
test 123 1
test 123 1
test 123 0


The program works by changing the boolean status from false(0) to true(1) when a particular line is processed.

However when there is an empty line at the very bottom of the input file, the program fails and the output text becomes meaningless. (The program works fine when there isn't an empty line though).

Is there any way to alter the code such that it skips the empty lines(if present)?

Thanks!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.