outputting words in array of text

This is a discussion on outputting words in array of text within the C++ Programming forums, part of the General Programming Boards category; does anyone know the function that will take an array of text and cut it up into words and also ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    12

    outputting words in array of text

    does anyone know the function that will take an array of text and cut it up into words and also cout different words;

    ex. I prompt the user to input some text and the i send that text to a function that couts each different word on a new line

  2. #2
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Where does the computer get the pair of scissors from into order to cut up the words?

    No, on a serious note you probably want to look at the function:

    Code:
    cin.getline

    and consider how do count white spaces since it is these which divides sentences into words.

    Then output the words onto separate lines

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Quote Originally Posted by hopeolicious
    does anyone know the function that will take an array of text and cut it up into words and also cout different words;

    ex. I prompt the user to input some text and the i send that text to a function that couts each different word on a new line
    1. Declare a string variable.
    2. Prompt user to enter a sentence.
    3. Call getline to stuff sentence into the string variable.
    4. Initialize an istringstream variable with the string input by user.
    5. Call the STL copy function to read from the istringstream variable and write to cout with a newline seperator after each word.

    That's it, 5 lines of code. Enjoy!
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    You COULD use a vector array of word and "puchback" tehm into the array, then map them out. That is how I believe chatterbots do it, and it allows for wordlist[i] to be used and all that.
    This war, like the next war, is a war to end war.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing Words from a text file
    By matt_570 in forum C++ Programming
    Replies: 18
    Last Post: 12-10-2008, 11:35 AM
  2. arrays vs lists? And containers in general!
    By clegs in forum C++ Programming
    Replies: 22
    Last Post: 12-03-2007, 01:02 PM
  3. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

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