I have a function template as this.
template<class T> T getFromString(const string& inStream)
{
istringstream stream (inStream);
T t;
stream >> t;
return t;
}
I am not getting how to use this function template. I have tried the usual method of using function template it was giving an error. Please let me know for getting out of this.
You can use it like this:
This will extract the integer value from the string.
BTW, it is good to use
T t = T();inside the template as it will gurantee the initialization for the basic datatypes even if the extaction fails.