C++ fstream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bnchs
    New Member
    • Mar 2007
    • 9

    #1

    C++ fstream

    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.

    Code:
     
    while (INFILE)
    {
     getline(INFILE, line) ;
    ...
    ...
    }
    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
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    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).

    Comment

    Working...