daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top