📄 716.cpp
字号:
//716.CPP demo iostream
#include <iostream.h>
main(void)
{
float a=100100.0, b=0.08;
long x= (-a*b) ,y= (a/b);
cout.setf(ios::showpos|ios::scientific);
cout<<(-a*b)<<" "<<(a/b)<<endl;
cout.unsetf(ios::showpos|ios::scientific);
cout.precision(4);
cout<<(-a*b)<<" "<<(a/b)<<endl;
cout<<x<<" "<<y<<endl;
cout << hex <<x<<" "<<y<<endl;
return 0;
}
/*
-8.008000e+03 +1.251250e+06
-8008 1.251e+06
-8007 1251250
ffffe0b9 1317b2
*/
/*
说明程序输出的格式:
第1行:指定了cout.setf(ios::showpos|ios::scientific);--showpos标志导致在显示正数时,前面加上正号"+";当设置scientific标志时,浮点数值以科学计数形式显示。
第2行:cout.unsetf(ios::showpos|ios::scientific);把上述标志取消后,同时设置了cout.precision(4);--要显示的有效数位数为4。
第3行:x,y是long类型,因此相当于进行了强制转换;不要奇怪,x把"-8008.000000"浮点数转换为-8007,因为浮点数往往不能用二进制完全精确表示,所以该数在内部可能是-8008.000001,或者-8007.999999;强制转换后就成-8007。
第4行:cout << hex <<x<<" "<<y<<endl;--把第3行的数用十六进制显示,因x是负值,所以显示ffffe0b9。
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -