Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. void split(const string& input, char separator, vector<string>& output) {
  10. stringstream inputStream(input);
  11.  
  12. string buff;
  13. while(getline(inputStream, buff, separator)) {
  14. output.push_back(move(buff));
  15. }
  16. }
  17.  
  18. int main() {
  19. string data = "Split me by spaces";
  20. vector<string> tokens;
  21. split(data, ' ', tokens);
  22.  
  23. for(string &token : tokens) {
  24. cout << token << endl;
  25. }
  26.  
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement