breaking input into individual words

Sep 30, 2014 at 6:39am
Write your question here.
hi, i was wondering if this piece of code was correct or could be corrected to return individual words from the input.
1
2
3
4
5
6
words_list paragraph_to_words( string& text ){		//a function that breaks the input text into words.
    words_list words;
    istringstream in(text);
    copy(istringstream_iterator<string>(in),istringstream_iterator<string>(),back_inserter(words));
    return words;
}

any suggestion will be helpful
Sep 30, 2014 at 8:36am
istringstream_iterator → istream_iterator
Other than that it could be fine depending on requirements.
Topic archived. No new replies allowed.