fork(6) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. istringstream iss("2.832 1.3067 nana1.678 xxx.05 meh.ugh");
  9. double num = 0;
  10. while(iss >> num || !iss.eof()) {
  11. if(iss.fail()) {
  12. iss.clear();
  13. while(iss) {
  14. char dummy = iss.peek();
  15. if(std::isdigit(dummy) || dummy == '.') {
  16. // Stop consuming invalid double characters
  17. break;
  18. }
  19. else {
  20. iss >> dummy; // Consume invalid double characters
  21. }
  22. }
  23. continue;
  24. }
  25. cout << num << endl;
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
2.832
1.3067
1.678
0.05