You can use stringstreams to convert from any type to anytype as long as the stream output from one type is readable as stream input from the other type.
Code:
#include <sstream>
#include <iostream>
// generalized notion of stream_casting
template <class outType, class inType>
outType stream_cast(const inType& in)
{
outType out;
std::ostringstream outStream;
outStream << in;
std::istringstream inStream(outStream.str());
inStream >> out;
return out;
}
int main() {
// specific example of stream casting
char numAsChar[]="1.532";
double numAsDouble;
std::ostringstream out;
out << numAsChar;
std::istringstream in(out.str());
in >> numAsDouble;
std::cout << numAsDouble << std::endl;
// use templated general stream cast
numAsDouble = stream_cast<double>(numAsChar);
std::cout << numAsDouble << std::endl;
return 0;
}