I am a beginner in c++, so the answer maybe obvious.
I have two functions - one is able to convert int into string and the other is able convert double into string. It would be more elegant however to unite these two into one. I have tried it with the code below, but it yields an error: ‘number’ was not declared in this scope
string number_into_string (void* data, int psize)
{
if (psize == sizeof(int))
{
int* number; number =(int*)data;
}
if (psize == sizeof(double))
{
double* number; number = (double*)data;
}
ostringstream convert;
convert << number;
string str = convert.str();
return str;
}
int main()
{
double x =1000;
int y = 5;
string str_x = number_into_string(&x, sizeof(x));
string str_y = number_into_string(&y, sizeof(y));
}