fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::stringstream file{"0.12000\n0.12000\n"};
  8. std::stringstream ss;
  9. std::string str;
  10. float f1, f2;
  11.  
  12. std::getline (file, str);
  13. ss.str(str);
  14. ss >> f1;
  15. if (ss.eof())
  16. std::cout << "eof reached after the extraction !!!!!"<<std::endl;
  17.  
  18. std::getline (file, str);
  19. ss.clear();
  20. ss.str(str);
  21. ss >> f2; //when packed inside if(), evalueates to false - but why it fails?
  22.  
  23.  
  24. std::cout<<"str = "<<str<<"\n";
  25. std::cout<<"ss.str() = "<<ss.str()<<"\n";
  26. std::cout<<"f1 = "<<f1<<"\nf2 = "<<f2<<"\n"; // your code goes here
  27. return 0;
  28. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
eof reached after the extraction !!!!!
str = 0.12000
ss.str() = 0.12000
f1 = 0.12
f2 = 0.12