All the examples I have sees on the web for creating a string with sprintf use a statically declared array whose size is fixed.
#include <stdio.h>
#include <math.h>
int main()
{
char str[80];
sprintf(str, "Value of Pi = %f", M_PI);
puts(str);
return(0);
}
I want to be able to do this with a dynamically sized array in the simplest way possible. I have to write some code that will print the values that compose the array:
printf("id=%s %s-array is: ", id.value(), name);
for (unsigned int i = 0; i < depths.size(); i++) {
printf("%f,", depths[i]);
}
printf("\n");
But I don't want to do this with separate printfs.. I want to be able to put it all in a buffer that fits the string I am writing at runtime. I am inclined to think that sprintf is the best way to do this, but if there are other functions I can use in C++. Let me know.