fork download
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4.  
  5. int main() {
  6. stringstream a("123");
  7. stringstream b("hello");
  8. int x;
  9. a >> x;
  10. if (!a.fail()) {
  11. cout << "a is fine: " << x << endl;
  12. } else {
  13. cout << "a is bad" << endl;
  14. }
  15. b >> x;
  16. if (!b.fail()) {
  17. cout << "b is fine: " << x << endl;
  18. } else {
  19. cout << "b is bad" << endl;
  20. }
  21. return 0;
  22. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
a is fine: 123
b is bad