cctype only returns in value... what Im trying to do is that i will input a string lets say "123" then the program will say "it is an integer" then it will convert to integer... If I will input "1.44" then it will say "it is a float" then it will convert it to "float" (for arithmetic operation)
you can do that with cctypes but whatever... if you want to write the code yourself then you can just use a regex library and then test for ints and floats
double IsFloat(std::string Buffer)
{
if(some_regex_match("[0-9]+\.[0-9]+", Buffer))
{
std::istringstream Stream(Buffer);
double TempFloat;
Stream >> TempFloat;
return TempFloat;
}
return 0.00000000000000000000000001 //i cant think of a better way to say it wasnt a float
}
then for the int just replace every instance of double with int, the [0-9]+\.[0-9]+ with [0-9]+ and return something other than 0.000...01
> i cant think of a better way to say it wasnt a float bool is_float(std::string)
your function may be better called `string_to_float'
in which in case of failure you could have returned 0, returned <0, returned `NaN', setting a global variable (errno), throwing an exception, returned a duple with a bool, or a boost optional
in which in case of failure you could have returned 0, returned <0, returned `NaN', setting a global variable (errno), throwing an exception, returned a duple with a bool, or a boost optional
good point. like i said i couldnt think of stuff at the moment
the functions in <cctype> work per character, so you'll have to write your parse function (which should take into account invalid constructions with valid characters)
However your reply seems to imply that it would be a trivial task like simply calling the `is_float()' function.
you forgot the minus sign in your regex
and scientific notation