Extracting Words in Strings Delimited by Whitespace
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main( )
{
string text( "this is a test" );
istringstream stream( text );
// make a vector with each word of the text
vector< string > words( (istream_iterator<string>( stream )),istream_iterator<string>() );
cout << words.size() << " : " << text;
}
Related examples in the same category