I am trying to save some double
variables to a file, but I would like for them to save with only 2 decimal places. If I were going to print them to terminal I would do this:
printf ("var1: %.2f var2: %.2f\n", var1, var2);
I would like to know if there is an equivalent but to use while writing to a file with fstream
.
I know in Java you can use PrintWriter
, for something like that, but is there a C++ equivalent?
Also I know I am double dipping here, but if I could also get a Java FileWriter
equivalent for C++ that would be great, because my program overwrites my file content, it doesn't append to it.