Advertisement
xxeell

string_to_double

Feb 26th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. #define ins in
  6. #define outs cout
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     ifstream in("input.txt");
  13.     ofstream out("output.txt");
  14.  
  15.     string t;
  16.     getline(ins, t);
  17.     double d;
  18.     size_t cnt;
  19.    
  20.     while (t.length() > 0)
  21.     {
  22.         try
  23.         {
  24.             d = stod(t, &cnt);
  25.             outs << d << " ";
  26.             t.erase(0, cnt);
  27.         }
  28.         catch (...)
  29.         {
  30.             t.erase(0, 1);
  31.         }
  32.     }
  33.     getc(stdin);
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement