Hello guys,
I wrote a function that converts any variable to a string using stringstream, the function is the following:
1 2 3 4 5 6 7 8
|
template <typename T>
std::string ToString(T const& value)
{
std::stringstream sstr;
sstr << sstr.scientific << value;
return sstr.str();
}
|
I call the function as follows:
string fileToOpen = string(filename.getValue() + string("_phi_") + ToString<T>(phi[ang]) + string("_theta_") + ToString<T>(theta[ang]) + string("_Iu_") + ToString<T>(laser.getLambertBeerSlope()) + string("_.bin"));
where all those variables to be converted to strings are doubles.
The problem is that the conversion always adds a "256" to the converted string, so I have:
theta[ang] = 9
phi[ang] = 37
laser.getLambertBeerSlope() = 1e-6
but the file name reads eventually:
FitData_phi_25637_theta_2569_Iu_2561e-06_.bin
Why does this "256" keep adding? has anyone faced such a problem before?
I'm using Ubuntu 12.04 and g++ in VMWare Workstation virtual machine (the problem showed up also on a Redhat/CentOS computer).
Thank you for any efforts.