In the following program
#include <fstream>
int main(){
std::ofstream fs_;
fs_.open("test.txt");
fs_<<1.f;
fs_<<" ";
fs_<<1.0;
fs_.flush();
fs_.close();
return 0;
}
Why the resulting file has written
1 1
instead of 1.0 1.0
? And is there a way to write them as floats or doubles?
I should have added that with floats with a lot of decimals I don't want them to be truncated.
So far with the suggested solution 1.034255
becomes 1.03
with precision of 2
Rather than the "duplicate" that this question was closed for, this question is more related to this one