Tassos icon

C++ split spaces from strings :)

Tassos | PRO | 01/13/15 09:07:59 PM UTC | 0 ⭐ | 454 👁️ | Never ⏰ | []
C++ |

680 B

|

None

|

0 👍

/

0 👎

#include <iostream>
#include <vector>
 
using namespace std;
 
int main() {
 
string s = "What is the right way to split a string into a vector of strings";
stringstream ss(s);
 
istream_iterator<string> begin(ss);
 
istream_iterator<string> end;
 
vector<string> vstrings(begin, end);
 
copy(vstrings.begin(), vstrings.end(), ostream_iterator<string>(cout, "\n"));
 
 
    return 0;
}
 
 
// by http://stackoverflow.com/questions/5607589/right-way-to-split-an-stdstring-into-a-vectorstring
 
/*
Other links info : 
http://stackoverflow.com/questions/5167625/splitting-a-c-stdstring-using-tokens-e-g
http://stackoverflow.com/questions/1894886/parsing-a-comma-delimited-stdstring
*/

Comments