Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <iostream>
- //#include <string>
- //setlocale(LC_ALL, "ru");
- template<typename T>
- T value_check() {
- bool was_point = false;
- std::string check;
- std::cin >> check;
- for (int i = 0; i < check.size(); i++) {
- if (check[i] == '.' || check[i] == ',' && !was_point) {
- check[i] = ',';
- was_point = true;
- }
- else if (check[i] == '.' || check[i] == ',' && was_point) {
- check.erase(check.begin() + i);
- i--;
- }
- if ((check[i] < 48 && check[i] != 43 && check[i] != 44 && check[i] != 45 && check[i] != 0) || check[i] > 57) {
- check.erase(check.begin() + i);
- i--;
- }
- }
- if (check[0] == '\0') {
- check += '0';
- }
- return static_cast<T>(std::stod(check));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement