读书人

流成员函数进行输入输出格式的控制解决

发布时间: 2012-04-24 14:15:38 作者: rapoo

流成员函数进行输入输出格式的控制
#include<iostream>
using namespace std;
int main()
{
cout.setf(ios::showpos|ios::scientific);
cout<<567<<" "<<567.89<<endl;
return 0;
}
这个题的编译结果是这样的:+567 +5.678900e+002
想知道showpos使得两个数都添加了“+”,为什么scientific不作用于两个数的,作用难道有顺序?
那如果是这样的cout.setf(ios::showpos|ios::dec|ios::scientific)呢?


[解决办法]
格式控制从不用cout,那是痛苦的代名词。
printf/scanf 强大无比
[解决办法]

探讨
#include<iostream>
using namespace std;
int main()
{
cout.setf(ios::showpos|ios::scientific);
cout<<567<<" "<<567.89<<endl;
return 0;
}
这个题的编译结果是这样的:+567 +5.678900e+002
想知道showpos使得两个数都添加了“+”……

[解决办法]
告别C++ 标准I/O库, 早日脱离苦海。

读书人网 >C++

热点推荐