Help with a vector of strings!

This is a discussion on Help with a vector of strings! within the C++ Programming forums, part of the General Programming Boards category; I need to write a C++ program taking a vector of strings and separating out the words in each, storing ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    3

    Help with a vector of strings!

    I need to write a C++ program taking a vector of strings and separating out the words in each, storing them into a vector, but I don't know how. Could anyone help me please?

    Code:
    Template Code:
    
    vector <string> seperateWords (vector<string> lines) {
        vector<string > words;
        
        //Separating stuff goes here
    
        return words;
    }
    Thanks in advance!

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Code:
    top: 
      Read in a line 
      position to start of line 
      wordfind: 
        find next non-blank - remember address #1 
        find next blank or end of string - whichever comes first - remember address #2 
        address #2 - address #1 = length of word 
        Using address #1 and length, add the string to your vector
      goto wordfind. 
    goto top.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    3
    Thanks. Could you please explain what you've done there?

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I wrote some pseudo code and enclosed it in [code] and [/code] tags.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Of course, in actual C++, you will find it a lot more comfortable to just use std::stringstream.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Quote Originally Posted by CornedBee View Post
    Of course, in actual C++, you will find it a lot more comfortable to just use std::stringstream.
    and operator>> to read from it part of the string upto next whitespace
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 02:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 07:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM

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