fork(2) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. bool read_double(std::istream & is, double & number)
  5. {
  6. std::string line;
  7. getline(is, line);
  8. std::size_t pos = 0;
  9. double temp = stod(line, &pos);
  10. if (pos != line.size()) // there is extra content in the streams
  11. return false;
  12. number = temp;
  13. return true;
  14. }
  15.  
  16.  
  17. int main()
  18. {
  19. double foo;
  20. std::cout << read_double(std::cin, foo);
  21. std::cout << read_double(std::cin, foo);
  22. std::cout << read_double(std::cin, foo);
  23. }
Success #stdin #stdout 0s 3460KB
stdin
1.5dog
1.5e5dog
1.5e3
stdout
001