Sign up to create your own snipts, or login.

Public snipts » Fotinakis's snipts » Tokenize a string in C++

posted on Sep 13, 2009 at 7:34 p.m. EDT in 
  • #include <string>
    #include <sstream>
    #include <algorithm>
    #include <iterator>
    #include <vector>
    using namespace std;
    
    int main() {
    	string sentence = "All of this has happened before...";
    	
    	vector<string> tokens;
    	istringstream iss(sentence);
    	copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens));
    }
    

    copy | embed

0 Comments

Sign up, or login to leave a comment.