I\'m trying to convert a string to a number. For that, I found the following way:
#include
#include
template
Try
int b = stringToNumber<int>(a);
Because the template type T
can not be deduced from any of the parameters (in this case std::string
) you need to explicitly define it.
You haven't supplied a template argument. Note that in C++11, you can use std::stoi
:
std::string a = "254";
int b = std::stoi(a);