Reading a word

This is a discussion on Reading a word within the C++ Programming forums, part of the General Programming Boards category; I have this simple problem that I can't figure out. I'm trying scan in a text doc. and look for ...

  1. #1
    jed
    jed is offline
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Reading a word

    I have this simple problem that I can't figure out. I'm trying scan in a text doc. and look for particular words. What would be the best way? I've tried using
    Code:
    get()
    and put it in a loop but it only grabs a character at a time. I've also tried
    Code:
     >>
    that stops at the white space and ends the program.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,535
    Same questions over and over again. Please do a search for reading from a file on these boards. There's also inumerous FAQs on the matter. Both on Cprog website as everywhere else in the web.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    whole line - getline();
    get - a character
    << a word, stops at a whitespace (space, tab, newline).

    There's some stringstream thing, I think, which does the whole file. Search search search!

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You'll probably need a loop of some kind too.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading Microsoft Word documents
    By Mavix in forum C# Programming
    Replies: 8
    Last Post: 08-04-2007, 08:39 AM
  2. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 08:55 PM
  3. reading file word by word
    By 98holb in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 05:49 PM
  4. Reading in a file word by word
    By Bumblebee11 in forum C Programming
    Replies: 4
    Last Post: 06-10-2003, 10:39 PM

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