Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- bool toNumberConv(std::string str, auto &x)
- {
- int dots = 0;
- bool num = true;
- unsigned int i = 0;
- while(i < str.length() && num)
- {
- if ((str[i] == '.') && dots == 0)
- {
- dots = 1;
- }
- else if (!isdigit(str[i]))
- {
- num = false;
- }
- i++;
- }
- if(num && dots == 0)
- {
- x = stoll(str);
- if(x <= 2147483647)
- {
- x = stoi(str);
- std::cout << "Ez egy int\n";
- }
- else
- {
- std::cout << "Ez egy long long\n";
- }
- }
- else if(num && dots == 1)
- {
- x = stod(str);
- std::cout << "Ez egy double\n";
- }
- else
- {
- x = -1;
- std::cout << "Nem sikerult a konvertalas\n";
- }
- return num;
- }
- /*
- int stoi -2,147,483,648 to 2,147,483,647
- long long int stoll -(2^63) to (2^63)-1
- double stod
- */
- int main()
- {
- std::string str;
- std::cin >> str;
- long double x;
- bool isNum = toNumberConv(str, x);
- if(isNum) std::cout << x << std::endl;
- else std::cout << "Ez nem egy szam\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement