| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2400 人关注过本帖
标题:关于cout.setf(ios_base ::showpoint)的一个问题
只看楼主 加入收藏
zhaoyg
Rank: 1
等 级:新手上路
帖 子:328
专家分:0
注 册:2006-8-28
收藏
 问题点数:0 回复次数:2 
关于cout.setf(ios_base ::showpoint)的一个问题
#include <iostream>

using namespace std;

int main()
{
    float a=2.4;

    cout <<"before showpoint,a="<<a<<endl;    //output 2.4

    ios_base ::fmtflags back=cout.setf(ios_base ::showpoint);

    cout <<"after showpoint,a="<<a<<endl;    //output 2.400000
    cout.setf(back);

    cout<<"after restore , a="<<a<<endl;     //还是 2.400000

    system ("pause");
    return 0;
}
为什么执行了cout.setf(back);后还是输出2.400000?
搜索更多相关主题的帖子: ios base cout setf showpoint 
2008-01-26 20:55
eagleboycn
Rank: 1
等 级:新手上路
帖 子:191
专家分:0
注 册:2007-9-26
收藏
得分:0 
用cout<<resetiosflags(ios::showpoint);可以啊
你用cout.setf(back);是甚么意思啊?
***********************************************************************
The function setf() sets the io stream format flags of the current stream to flags. The optional needed argument specifies that only the flags that are in both flags and needed should be set. The return value is the previous configuration of io stream format flags.
*******************************************************************
resetiosflags( long f )
Turn off the flags specified by f

兵法的精要在于韬晦自己
2008-01-26 22:41
zhaoyg
Rank: 1
等 级:新手上路
帖 子:328
专家分:0
注 册:2006-8-28
收藏
得分:0 
书上当时说是用cout.setf(back)就可以返回到默认状态,但我试了半天都没有看到效果。
其中back保存的是默认值

[[italic] 本帖最后由 zhaoyg 于 2008-1-26 22:46 编辑 [/italic]]

麻雀飞上枝头变凤凰,而菜鸟的我飞上枝头却感冒了,为什么我的脑袋如此的不管用呢。
2008-01-26 22:45
快速回复:关于cout.setf(ios_base ::showpoint)的一个问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014209 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved