fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int to_digit(char c) {
  5. if(c >= '0' && c <= '9') {
  6. return c-'0';
  7. }
  8. std::cerr << "[" << c << "] TO NIE CYFRA!11!!" << std::endl;
  9. return 0;
  10. }
  11.  
  12. int to_number(std::string const &str) {
  13. try {
  14. return std::stoi(str);
  15. } catch(...) {}
  16. std::cerr << "[" << str << "] TO NIE LICZBA!11!!" << std::endl;
  17. return 0;
  18. }
  19.  
  20. int main() {
  21. using namespace std;
  22. cout << to_digit('9') << endl;
  23. cout << to_digit('@') << endl;
  24. cout << to_number("-123") << endl;
  25. cout << to_number("-kappa") << endl;
  26. return 0;
  27. }
Success #stdin #stdout #stderr 0s 3472KB
stdin
Standard input is empty
stdout
9
0
-123
0
stderr
[@] TO NIE CYFRA!11!!
[-kappa] TO NIE LICZBA!11!!