enum {  skipws     = 0x0001,
            left       = 0x0002,
            right      = 0x0004,
            internal   = 0x0008,
            dec        = 0x0010,
            oct        = 0x0020,
            hex        = 0x0040,
            showbase   = 0x0080,
            showpoint  = 0x0100,
            uppercase  = 0x0200,
            showpos    = 0x0400,
            scientific = 0x0800,
            fixed      = 0x1000,
            unitbuf    = 0x2000,
            stdio      = 0x4000
          };    static const long basefield;        // dec | oct | hex
    static const long adjustfield;      // left | right | internal
    static const long floatfield;       // scientific | fixedios类中的一段代码,有函数out.setf(ios::hex,ios::basefield)  这个函数的第二个参数好理解,就是IOS类的那个basefield变量成员,但是第一个参数是咋回事,咋 ios::hex 就用上了,我认为应该这样定义下 static long hex , 才可以这ios::hex 用吧,不知道我那理解错了???

解决方案 »

  1.   

    看setf函数源码,它内部应该是把第一个参数保存了。
      

  2.   

    这可是ios.h原文件里面的内容,我当时是看到书上这么介绍的,很是奇怪,能后在电脑上看ios.h这个源文件,还真是这样的,可以在自己的电脑上看看ios.h这个文件~~~~~
      

  3.   

    我是问out.setf(ios::hex,ios::basefield)里面的ios::hex这个参数是怎么回事,应该跟setf函数没关系吧。。
      

  4.   

    这里的ios::hex只是个枚举性常量,也就是0x0040。
    VC6函数实现代码:
    inline long ios::setf(long _l, long _m)
    {
        ...
        x_flags = (_l&_m) | (x_flags&(~_m))
        ...
    }第一个参数的设置直接影响类的x_flags变量.
      

  5.   

        enum {  skipws    = 0x0001, 
                left      = 0x0002, 
                right      = 0x0004, 
                internal  = 0x0008, 
                dec        = 0x0010, 
                oct        = 0x0020, 
                hex        = 0x0040, 
                showbase  = 0x0080, 
                showpoint  = 0x0100, 
                uppercase  = 0x0200, 
                showpos    = 0x0400, 
                scientific = 0x0800, 
                fixed      = 0x1000, 
                unitbuf    = 0x2000, 
                stdio      = 0x4000 
              }; 
    如果是等效于
    const long          kipws    = 0x0001, 
    const long          left      = 0x0002, 
    const long          right      = 0x0004, 
    const long          internal  = 0x0008, 
    const long          dec        = 0x0010, 
    const long          oct        = 0x0020, 
    const long          hex        = 0x0040, 
    const long          showbase  = 0x0080, 
    const long          showpoint  = 0x0100, 
    const long          uppercase  = 0x0200, 
    const long          showpos    = 0x0400, 
    const long          scientific = 0x0800, 
    const long          fixed      = 0x1000, 
    const long          unitbuf    = 0x2000, 
    const long          stdio      = 0x4000,就好理解out.setf(ios::hex,ios::basefield)里面的ios::hex这个参数,楼上的还是没说清楚ios::hex这个参数这个参数是怎么回事,
    上面的等式效果成立不?
      

  6.   

    ios::hex这个参数是让cout输出数字时以16进制格式输出。
      

  7.   

    恩 我知道ios::hex这个参数的意思,但是hex这个成员变量在IOS.H中是那样定义的,看起来是不是非常的奇异,要是是这样定义的
    const long hex = 0x0040;
    那就很正常,我这里说的不是什么别的,只是说为啥是这样定义的    
         enum {  skipws    = 0x0001, 
                left      = 0x0002, 
                right      = 0x0004, 
                internal  = 0x0008, 
                dec        = 0x0010, 
                oct        = 0x0020, 
                hex        = 0x0040, 
                showbase  = 0x0080, 
                showpoint  = 0x0100, 
                uppercase  = 0x0200, 
                showpos    = 0x0400, 
                scientific = 0x0800, 
                fixed      = 0x1000, 
                unitbuf    = 0x2000, 
                stdio      = 0x4000 
              }; 这里怎么这样定义,为什么这样定义,没见过这样的,根本不理解这是个什么样的语法规则,是不是我在七楼说的等效于娜一段定义代码????
      

  8.   

    就是编程习惯问题。
    STL里面有很多这样的定义的。