fork(1) download
  1. #include <string>
  2. #include <vector>
  3. #include <iterator>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <sstream>
  7. using namespace std;
  8.  
  9. vector<int> doit(string s)
  10. {
  11. s.erase(remove(s.begin(), s.end(), ','));
  12. istringstream buf(s);
  13. return vector<int>(istream_iterator<int>(buf), istream_iterator<int>());
  14. }
  15.  
  16. int main()
  17. {
  18. string s1 = "0, 1, 3, 2";
  19. vector<int> v1 = doit(s1);
  20. for(size_t n = 0; n < v1.size(); ++n)
  21. cout << v1[n] << ' ';
  22. cout << '\n';
  23.  
  24. string s2 = "-1, -1, 1, 1, 1, -1, -1, 1";
  25. vector<int> v2 = doit(s2);
  26. for(size_t n = 0; n < v2.size(); ++n)
  27. cout << v2[n] << ' ';
  28. cout << '\n';
  29.  
  30. }
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout
0 1 3 2 2 
-1 -1 1 1 1 -1 -1 1 -1