Connecting Tech Pros Worldwide Forums | Help | Site Map

C++ fstream

Newbie
 
Join Date: Mar 2007
Posts: 9
#1: Mar 23 '07
I am have tried unsuccessfully to remove or ignore lines that contain integers from an input file. This is what I am using to extract lines from the file. I have looked up the ignore() function but I don't think that will help me do this. Does anyone have any suggestions? Thanks.

Expand|Select|Wrap|Line Numbers
  1.  
  2. while (INFILE)
  3. {
  4.  getline(INFILE, line) ;
  5. ...
  6. ...
  7. }
  8.  
  9.  
The input file contains data like:
10
Who are you
5
I Know
15
Parliamentary


I am trying to get the string line to receive :

Who are you
I Know
Parliamentary

Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,180
#2: Mar 23 '07

re: C++ fstream


I do not think you will have much success becuase getline gets a line (the clue is in the function name) from a file.

Since you data is spread accross multiple lines in the file it will require several getline calls to retrieve it.

You need to load the lines individually make the decision on whether to keep or discard them and if keeping them add them to the store of kept lines (which you will also have to create).
Reply


Similar C / C++ bytes