问题描述
我需要防止我的双面以我的文件中的科学记数法打印,
当我这样做
outfile< X;
要设置浮动变量的格式, , a href =http://en.cppreference.com/w/cpp/io/manip/showpoint> showpoint
和。为了使用 setprecision(n)
这样的参数化流操作符,你必须包括iomanip库:
#include< iomanip>
setprecision(n)
:将限制浮动输出到 n
个地方,一旦你设置它,它被设置,直到你显式地取消它为流输出的剩余部分。
fixed
:将强制所有浮点数以相同的方式输出。因此,如果您的精度设置为4个位置,则 6.2
和 6.20
6.2000
6.2000
showpoint
:将强制显示浮点变量的小数部分,即使没有显式设置。例如, 4
将输出为:
4.0 $ b $ code> outfile<<固定<显示点
outfile<< setprecision(4);
outfile<< X;
I need to prevent my double to print in scientific notation in my file,
when I do this
outfile << X;
To set formatting of floating variables you can use a combination of setprecision(n)
, showpoint
and fixed
. In order to use parameterized stream manipulators like setprecision(n)
you will have to include the iomanip library:
#include <iomanip>
setprecision(n)
: will constrain the floating-output to n
places, and once you set it, it is set until you explicitly unset it for the remainder of the stream output.
fixed
: will enforce that all floating-point numbers are output the same way. So if your precision is set to 4 places, 6.2
, and 6.20
will both be output as:
6.2000
6.2000
showpoint
: will force the decimal portions of a floating-point variable to be displayed, even if it is not explicitly set. For instance, 4
will be output as:
4.0
Using them all together:
outfile << fixed << showpoint;
outfile << setprecision(4);
outfile << x;
这篇关于当使用<<<有双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!