I have to print a floating point value, however the precision is not known at compile time. So this parameter has to be passed as agument. How this can be achieved. In windows, with CString, the format function helps to achieve this. How to achieve this without CString. Code:
int main()
{
/* This below code segment works fine.*/
char str[80];
sprintf(str, "Value of Pi = %.3f", 3.147758);
std::cout << str << std::endl; //Prints "Value of Pi = 3.148"
/* When the precision may vary, henc It needs to be printed required on that.*/
char str2[80];
std::string temp = "%.3f"; //This is required as the precision may change.
// i.e I may have 4 instead 3 decimal points.
sprintf(str2, "Value = %s", temp, 3.148257);
std::cout << str2 << std::endl; //Prints "Value = <null>"
return 0;
}