It was not clear from the question that you want the setprecision
to modify how fprintf
works; it's only clear from the comments.
This is impossible (at least, with the existing C++ standard library).
The stdio
and iostreams
systems are separate, mostly independent parts in C++. In addition, the iostreams
stuff was standardized after the stdio
stuff, so to support having setprecision
affect fprintf
would mean changing fprintf
code, which no one wants to do.
To give an idea on how separate they are, look at ios_base::sync_with_stdio
- a dedicated function to make fpritnf
and operator<<
interoperate.
To make your system work, you probably have to replace fprintf
by operator<<
. Another way would be adjusting the fprintf
's format string, but you would have to add the obscure call to ios_base::sync_with_stdio
to your code.