fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main() {
  6. for (auto s : {"-123", "--123", "+123", "++123", "00.00"}) {
  7. cout << "'" << s << "': ";
  8. int64_t x{};
  9. if (sscanf(s, "%li", &x)) {
  10. cout << x;
  11. } else {
  12. cout << "CANNOT PARSE";
  13. }
  14. cout << endl;
  15. }
  16. return 0;
  17. }
Success #stdin #stdout 0.01s 5424KB
stdin
Standard input is empty
stdout
'-123': -123
'--123': CANNOT PARSE
'+123': 123
'++123': CANNOT PARSE
'00.00': 0