fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <vector>
  4. //#include <fstream>
  5. #include <sstream>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. int main (){
  10. istream &infile = cin;
  11. /*ifstream infile("tested");
  12. if (!infile.is_open()){
  13. cout << "File did not open" << endl;
  14. }
  15. else*/{
  16. vector<int> vect;
  17. string line;
  18. while (getline(infile, line)) {
  19. istringstream iss(line);
  20. int x; char c;
  21. while (iss >> x) {
  22. cout << x + 1 << endl;
  23. vect.push_back(x);
  24. iss >> c;
  25. }
  26. }
  27.  
  28. cout << "before sort" << endl;
  29. for (size_t i = 0; i < vect.size(); ++i){
  30. cout << vect[i] << endl;
  31. }
  32.  
  33. sort(vect.begin(), vect.end());
  34.  
  35. cout << "after sort" << endl;
  36. for (int j = 0; j < vect.size(); ++j){
  37. cout << vect[j] << endl;
  38. }
  39.  
  40. cout << "end reached" << endl;
  41. }
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 4304KB
stdin
1,2,4,6,8,12,12, 
stdout
2
3
5
7
9
13
13
before sort
1
2
4
6
8
12
12
after sort
1
2
4
6
8
12
12
end reached