40 lines
890 B
C++
40 lines
890 B
C++
#pragma once
|
|
#include <string>
|
|
#include <stdexcept>
|
|
|
|
class ConverType
|
|
{
|
|
public:
|
|
static int TryToI(const std::string& input){
|
|
int ret = INT_MIN;
|
|
try {
|
|
ret = stoi(input);
|
|
return ret;
|
|
}
|
|
catch (const std::invalid_argument& e) {
|
|
printf("input is not number...\n");
|
|
}
|
|
catch (const std::out_of_range& e) {
|
|
printf("input number is out of int range...\n");
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static float TryToF(const std::string& input) {
|
|
float ret = -1.0;
|
|
try {
|
|
ret = stof(input);
|
|
return ret;
|
|
}
|
|
catch (const std::invalid_argument& e) {
|
|
printf("input is not float...\n");
|
|
}
|
|
catch (const std::out_of_range& e) {
|
|
printf("input number is out of float range...\n");
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
};
|
|
|