首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

ios类输入输出格式控制函数setf的含义解决办法

2012-02-06 
ios类输入输出格式控制函数setf的含义在ios类中setf(long_l,long_m)函数完成格式控制,其中_l表示在原标识

ios类输入输出格式控制函数setf的含义
在ios类中setf(long   _l,long   _m)函数完成格式控制,其中_l表示在原标识字x_flag上新增加的控制,_m表示取代原来哪几位,程序如下
{long   _l0;
_l0=x_flag;
x_flag=(_l   &   _m)|(x_flag&(~_m));
return   _l0;}
本人理解只要_l|(x_flag&(~_m))即可,为什么要_l   &   _m这一步,如果_l为4,_m为3,_l   &   _m岂不是=0了

[解决办法]
setf
Syntax:

#include <fstream>
fmtflags setf( fmtflags flags );
fmtflags setf( fmtflags flags, fmtflags needed );

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.

For example:

int number = 0x3FF;
cout.setf( ios::dec );
cout < < "Decimal: " < < number < < endl;
cout.unsetf( ios::dec );
cout.setf( ios::hex );
cout < < "Hexadecimal: " < < number < < endl;

Note that the preceding code is functionally identical to:

int number = 0x3FF;
cout < < "Decimal: " < < number < < endl < < hex < < "Hexadecimal: " < < number < < dec < < endl;

热点排行