fork(3) download
  1. #include <iostream>
  2. #include <ios>
  3. #include <sstream>
  4.  
  5. int main()
  6. {
  7. std::cout << std::boolalpha;
  8. const char* inputs[] = { "14", "abc", "14a", "-14", nullptr };
  9. for (int i = 0; inputs[i]; i++)
  10. {
  11. std::istringstream in(inputs[i]);
  12. int j;
  13.  
  14. std::cout << inputs[i]
  15. << " valid integer ? "
  16. << (in >> j && in.eof())
  17. << "\n";
  18. }
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
14 valid integer ? true
abc valid integer ? false
14a valid integer ? false
-14 valid integer ? true