Advertisement
tranerius

value_check

Feb 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. //#include <iostream>
  2. //#include <string>
  3. //setlocale(LC_ALL, "ru");
  4.  
  5. template<typename T>
  6. T value_check() {
  7.     bool was_point = false;
  8.     std::string check;
  9.     std::cin >> check;
  10.     for (int i = 0; i < check.size(); i++) {
  11.         if (check[i] == '.' || check[i] == ',' && !was_point) {
  12.             check[i] = ',';
  13.             was_point = true;
  14.         }
  15.         else if (check[i] == '.' || check[i] == ',' && was_point) {
  16.             check.erase(check.begin() + i);
  17.             i--;
  18.         }
  19.         if ((check[i] < 48 && check[i] != 43 && check[i] != 44 && check[i] != 45 && check[i] != 0) || check[i] > 57) {
  20.             check.erase(check.begin() + i);
  21.             i--;
  22.         }
  23.     }
  24.     if (check[0] == '\0') {
  25.         check += '0';
  26.     }
  27.     return static_cast<T>(std::stod(check));
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement