Tassos

C++ split spaces from strings :)

Jan 13th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. string s = "What is the right way to split a string into a vector of strings";
  9. stringstream ss(s);
  10.  
  11. istream_iterator<string> begin(ss);
  12.  
  13. istream_iterator<string> end;
  14.  
  15. vector<string> vstrings(begin, end);
  16.  
  17. copy(vstrings.begin(), vstrings.end(), ostream_iterator<string>(cout, "\n"));
  18.  
  19.  
  20.     return 0;
  21. }
  22.  
  23.  
  24. // by http://stackoverflow.com/questions/5607589/right-way-to-split-an-stdstring-into-a-vectorstring
  25.  
  26. /*
  27. Other links info :
  28. http://stackoverflow.com/questions/5167625/splitting-a-c-stdstring-using-tokens-e-g
  29. http://stackoverflow.com/questions/1894886/parsing-a-comma-delimited-stdstring
  30. */
Advertisement
Add Comment
Please, Sign In to add comment