Skip to content

Instantly share code, notes, and snippets.

@abhi1010
Forked from anonymous/gist:0465925390f3442a7691
Last active September 2, 2015 14:18
Show Gist options
  • Save abhi1010/554885a7235f4047dae6 to your computer and use it in GitHub Desktop.
Save abhi1010/554885a7235f4047dae6 to your computer and use it in GitHub Desktop.
Tokenize a String
string strToSplit = "splitting strings, in|multiple ways";
std::vector<std::string> words;
boost::split(words, strToSplit, boost::is_any_of("\t ,|"));
std::copy (words.begin(), words.end(), std::ostream_iterator<string>(cout, "\n"));
words.clear();
std::istringstream iss(strToSplit);
std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(), std::back_inserter(words));
std::copy (words.begin(), words.end(), std::ostream_iterator<string>(cout, "\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment