关于输入输出的问题

w66187564 2008-03-02 02:50:40
以下一段代码:
#include <iostream>
using namespace std;
void main()
{
class point
{
public:
void setx(double px)
{
x=px;
}
void sety(double py)
{
y=py;
}
void printpoint()
{
cout<<"x="<<x<<",y="<<y<<endl;
}
private:
double x;
double y;
};
point p;
p.sety(7.0);
p.setx(4.0);
p.printpoint();
}
输出结果为什么是4和7而不是4.0和7.0呢?
x和y不是都是double类型的吗?
...全文
105 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
laolaoliu2002 2008-03-02
  • 打赏
  • 举报
回复
你可以控制输出多少,你输入的就是4.0&7.0
arong1234 2008-03-02
  • 打赏
  • 举报
回复
为什么不是4.00, 而要4.0?
Mnky 2008-03-02
  • 打赏
  • 举报
回复
cout<<"x="<<setprecision(1)<<x;
  • 打赏
  • 举报
回复
你看一下这个例子.

#include <iostream>

int main( )
{
using namespace std;
double f1= 5.000;
cout << f1 << endl; // noshowpoint is default
cout.precision( 4 );
cout << showpoint << f1 << endl;
cout << noshowpoint << f1 << endl;
}

输出
5
5.000
5
laolaoliu2002 2008-03-02
  • 打赏
  • 举报
回复
Double precision values with double type have 8 bytes. The format is similar to the float format except that it has an 11-bit excess-1023 exponent and a 52-bit mantissa, plus the implied high-order 1 bit. This format gives a range of approximately 1.7E–308 to 1.7E+308 for type double.

Microsoft Specific

The double type contains 64 bits: 1 for sign, 11 for the exponent, and 52 for the mantissa. Its range is +/–1.7E308 with at least 15 digits of precision.
laolaoliu2002 2008-03-02
  • 打赏
  • 举报
回复
double x;
double y;
就要输出4.0&7.0了.
相关推荐
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-03-02 02:50
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下