fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <exception>
  5. int main()
  6. {
  7. std::vector<int> v;
  8. std::string number = "+-1234567";
  9. for(auto& Integer: number)
  10. {
  11. std::string Char(1, Integer); // convert to string
  12. try { v.emplace_back(std::stoi(Char)); }
  13. catch(...) { continue; } // any case of exceptions
  14. }
  15. for(const auto& it: v) std::cout << it << " ";
  16. }
  17.  
Success #stdin #stdout 0s 4208KB
stdin
Standard input is empty
stdout
1 2 3 4 5 6 7