I'm trying to convert a string to a number. For that, I found the following way:
#include <iostream>
#include <string>
template <typename T>
T stringToNumber(const std::string &s)
{
std::stringstream ss(s);
T result;
return ss >> result ? result : 0;
}
int main()
{
std::string a = "254";
int b = stringToNumber(a);
std::cout << b*2 << std::endl;
}
The problem is that I am getting the following error:
error: no matching function for call to ‘stringToNumber(std::string&)’
May anyone tell me why I am getting such error and how to fix it?
Thank you in advance.