Thread: Clearing out an input line

  1. #1
    Unregistered
    Guest

    Question Clearing out an input line

    Hello,

    I'm having a hell of a time trying to figure out how to do something pretty simple. What I'm trying to do is read in lines from a file and discard extra stuff after I've gotten what I want. Here's an example:

    (DA, 15, 16, 5) blah blah blah
    (NW, 11, 10, 23) blah

    I want to extract the info between the parantheses, which I can do, but I also need to clear out the rest of the garbage (blah blah blah) on each line until I hit an end of line character. I can't get this to work for some reason and was wondering if anybody knew the right way to do it. Any help would be appreciated.

    -Adam

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Are you using c++ streams to do the read, or some other method? If you are using streams, are you using getline to read each line? For example:

    in.getline(line,80);

  3. #3
    Unregistered
    Guest
    you can use getline() and ignore() to help you parse the line

    if the file doesn't contain the parenthesis but does contain the commas and spaces as listed and fin is ifstream associated with file where data is found then:

    get first input
    fin.getline(buffer, 3, ',')

    ignore the space between frist and second input
    fin.ignore(1, ' ');

    get second input
    fin.getline(buffer2, 3, ',')

    ignore the space between second and third input
    fin.ignore(1, ' ');

    get third input as you did first and second

    ignore space between third and fourth input

    get fourth input using >> instead of getline as there is no comma delimiting fourth from fifth input

    use getline() to read into dummy buffer that will be ignored in your code using say an 80 char buffer to be sure you can hold everything you want disregard, and using newline char as terminating char for getline.

    now move on to the next line, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. calling a spesific line from input file
    By serap in forum C++ Programming
    Replies: 4
    Last Post: 04-02-2002, 06:42 AM
  3. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM
  4. clearing input stream
    By Sub in forum C++ Programming
    Replies: 2
    Last Post: 01-21-2002, 08:59 PM