These functions, to some, may seem trivial, but many people have queried in the forums on this topic numerous times.
The functions are templated, so that it can accommodate any data-type that the user wishes to use (For example, the same function can be used for converting variables of type long
, int
, double
etc into strings, and vice-versa).
The first function, Fn I ( convertToString
), is capable of converting a variable of any data-type into a string.
Sample Function Call:
string MyInt = convertToString<int>(10);
The second function, Fn II ( convertFromString
), can convert a string into a variable of any data-type.
Sample Function Call:
int MyNumber = convertFromString<int>("45");
*Note*: You will have to include the header files - <sstream>
and <string.h>
for the code to work...
Hope this snippet helps....