Ignoring a word from a .txt file

This is a discussion on Ignoring a word from a .txt file within the C++ Programming forums, part of the General Programming Boards category; Im wondering if there is a way to skip a word when reading text in with fstream. I know that ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Ignoring a word from a .txt file

    Im wondering if there is a way to skip a word when reading text in with fstream. I know that there is the seekg() and tell(g) functions, but they don't have the nice 'ignore all whitespace and just eat the next word' ability. Neither does .ignore() seem to. Right now Im just skipping words by cin'ing thm into a garbage variable...but I wonder if theres a better way?

    I had rigged up a function using seekg to skip to the next white space...but my file has multiple spaces in a row sometimes and it would screw up there unless I called it for each white space. Im looking for a function that really works the same as just cin'ing the word into a garbage variable.
    ______________________
    The Gekko

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    3
    possibly the function you rigged up would work if you set up a "last_word" variable-

    If last_word!=fget(word) && last_word!=" " {
    do stuff();
    last_word=new word;
    }


    Then only when you get a new word, and both the last word and the new word are not blank will the function be called.

    As to the actual question, I don't know of a method off hand.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  3. Read word from text file (It is an essay)
    By forfor in forum C Programming
    Replies: 7
    Last Post: 05-08-2003, 11:45 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21