Extracting Words in Strings Delimited by Whitespace : string « String « C++






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

1.Define a string variable, assign a value and display it
2.string basics
3.copy constructor
4.Changing Case in Strings
5.A short string demonstration.A short string demonstration.
6.Loop through the string array
7.Char Escapes