I am using setf in for displaying decimal places in outputs.
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
However, when I put the above code before an output, other outputs are affected too. Is there any way I can use setf for just only a single output? Like turning it off?
Thank you a lot!
setf
returns the original flag value, so you can simply store that then put it back when you're done.The same is true of
precision
.So:
Read some documentation.