fork download
  1. #include <iostream>
  2. #include <float.h>
  3. #include <string>
  4. #include <sstream>
  5. using namespace std;
  6.  
  7. inline double convertToDouble(std::string const& s)
  8. {
  9. std::istringstream i(s);
  10. double x;
  11. if (!(i >> x)){
  12. //throw BadConversion("convertToDouble(\"" + s + "\")");
  13. cout <<"blad";
  14. }
  15. return x;
  16. }
  17.  
  18. size_t jakDlugiDouble() {
  19. string sDouble = to_string(DBL_MAX);
  20. return sDouble.size();
  21. }
  22.  
  23.  
  24. double czyLiczba () {
  25. string sLiczba = "";
  26. cin >> sLiczba;
  27. if (sLiczba.size() > jakDlugiDouble()) {
  28. //throw TooLongNumber("convertToDouble(\"" + s + "\")");
  29. }
  30. return convertToDouble(sLiczba);
  31. }
  32.  
  33.  
  34. int main() {
  35. cout.setf(ios::fixed, ios::floatfield);
  36. cout.setf(ios::showpoint);
  37. //while(cin) {
  38. double liczba = czyLiczba();
  39. cout << ' ' << liczba<<endl;
  40. // }
  41. return 0;
  42. }
Success #stdin #stdout 0s 3480KB
stdin
123.@32
stdout
 123.000000