IO Stream Manipulator

来源:互联网 发布:海盗湾电影源码 编辑:程序博客网 时间:2024/05/17 06:53
VC++2005 SRC里面的源代码:

// 27.4.5, manipulators:ios_base& boolalpha (ios_base& str);ios_base& noboolalpha(ios_base& str);ios_base& showbase (ios_base& str);ios_base& noshowbase (ios_base& str);ios_base& showpoint (ios_base& str);ios_base& noshowpoint(ios_base& str);ios_base& showpos (ios_base& str);ios_base& noshowpos (ios_base& str);ios_base& skipws (ios_base& str);ios_base& noskipws (ios_base& str);ios_base& uppercase (ios_base& str);ios_base& nouppercase(ios_base& str);ios_base& unitbuf (ios_base& str);ios_base& nounitbuf (ios_base& str);// 27.4.5.2 adjustfield:ios_base& internal (ios_base& str);ios_base& left (ios_base& str);ios_base& right (ios_base& str);// 27.4.5.3 basefield:ios_base& dec (ios_base& str);ios_base& hex (ios_base& str);ios_base& oct (ios_base& str);//27.4.5.4 floatfield:ios_base& fixed (ios_base& str);ios_base& scientific (ios_base& str);

上面这些是用于cout<<showbase之类的方式。
调用的函数是:
    _Myt& __CLR_OR_THIS_CALL operator<<(ios_base& (__cdecl *_Pfn)(ios_base&))
        {    // call ios_base manipulator
        _DEBUG_POINTER(_Pfn);
        (*_Pfn)(*(ios_base *)this);
        return (*this);
        }















下面这些是用于cout.setf(ios::fixed);之类的,调用的函数是:
    fmtflags __CLR_OR_THIS_CALL setf(fmtflags _Newfmtflags)
        {    // merge in format flags argument
        ios_base::fmtflags _Oldfmtflags = _Fmtfl;
        _Fmtfl = (fmtflags)((int)_Fmtfl
            | (int)_Newfmtflags & (int)_Fmtmask);
        return (_Oldfmtflags);
        }
看看下面这些枚举型变量的定义:
#define _IOSskipws        0x0001
 #define _IOSunitbuf    0x0002
 #define _IOSuppercase    0x0004
 #define _IOSshowbase    0x0008
 #define _IOSshowpoint    0x0010
 #define _IOSshowpos    0x0020
 #define _IOSleft        0x0040
 #define _IOSright        0x0080
 #define _IOSinternal    0x0100
 #define _IOSdec        0x0200
 #define _IOSoct        0x0400
 #define _IOShex        0x0800
 #define _IOSscientific    0x1000
 #define _IOSfixed        0x2000
 #define _IOShexfloat    0x3000    /* added with C99 */
 #define _IOSboolalpha    0x4000
 #define _IOS_Stdio        0x8000

 #define _IOS_Nocreate    0x40
 #define _IOS_Noreplace    0x80
 #define _IOSbinary        0x20
        // TEMPLATE CLASS _Iosb
template<class _Dummy>
    class _Iosb
    {    // define templatized bitmask/enumerated types, instantiate on demand
public:
    enum _Dummy_enum {_Dummy_enum_val = 1};    // don't ask

    enum _Fmtflags
        {    // constants for formatting options
        _Fmtmask = 0xffff, _Fmtzero = 0};

    static const _Fmtflags skipws = (_Fmtflags)_IOSskipws;
    static const _Fmtflags unitbuf = (_Fmtflags)_IOSunitbuf;
    static const _Fmtflags uppercase = (_Fmtflags)_IOSuppercase;
    static const _Fmtflags showbase = (_Fmtflags)_IOSshowbase;
    static const _Fmtflags showpoint = (_Fmtflags)_IOSshowpoint;
    static const _Fmtflags showpos = (_Fmtflags)_IOSshowpos;
    static const _Fmtflags left = (_Fmtflags)_IOSleft;
    static const _Fmtflags right = (_Fmtflags)_IOSright;
    static const _Fmtflags internal = (_Fmtflags)_IOSinternal;
    static const _Fmtflags dec = (_Fmtflags)_IOSdec;
    static const _Fmtflags oct = (_Fmtflags)_IOSoct;
    static const _Fmtflags hex = (_Fmtflags)_IOShex;
    static const _Fmtflags scientific = (_Fmtflags)_IOSscientific;
    static const _Fmtflags fixed = (_Fmtflags)_IOSfixed;
    static const _Fmtflags boolalpha = (_Fmtflags)_IOSboolalpha;
    static const _Fmtflags _Stdio = (_Fmtflags)_IOS_Stdio;
    static const _Fmtflags adjustfield = (_Fmtflags)(_IOSleft
        | _IOSright | _IOSinternal);
    static const _Fmtflags basefield = (_Fmtflags)(_IOSdec
        | _IOSoct | _IOShex);
    static const _Fmtflags floatfield = (_Fmtflags)(_IOSscientific
        | _IOSfixed);

    enum _Iostate
        {    // constants for stream states
        _Statmask = 0x17};

    static const _Iostate goodbit = (_Iostate)0x0;
    static const _Iostate eofbit = (_Iostate)0x1;
    static const _Iostate failbit = (_Iostate)0x2;
    static const _Iostate badbit = (_Iostate)0x4;
    static const _Iostate _Hardfail = (_Iostate)0x10;

    enum _Openmode
        {    // constants for file opening options
        _Openmask = 0xff};

    static const _Openmode in = (_Openmode)0x01;
    static const _Openmode out = (_Openmode)0x02;
    static const _Openmode ate = (_Openmode)0x04;
    static const _Openmode app = (_Openmode)0x08;
    static const _Openmode trunc = (_Openmode)0x10;
    static const _Openmode _Nocreate = (_Openmode)_IOS_Nocreate;
    static const _Openmode _Noreplace = (_Openmode)_IOS_Noreplace;
    static const _Openmode binary = (_Openmode)_IOSbinary;

    enum _Seekdir
        {    // constants for file positioning options
        _Seekmask = 0x3};
    static const _Seekdir beg = (_Seekdir)0;
    static const _Seekdir cur = (_Seekdir)1;
    static const _Seekdir end = (_Seekdir)2;

    enum
        {    // constant for default file opening protection
        _Openprot = _SH_DENYNO};
    };


typedef T1 fmtflags;static const fmtflags boolalpha;static const fmtflags dec;static const fmtflags fixed;static const fmtflags hex;static const fmtflags internal;static const fmtflags left;static const fmtflags oct;static const fmtflags right;static const fmtflags scientific;static const fmtflags showbase;static const fmtflags showpoint;static const fmtflags showpos;static const fmtflags skipws;static const fmtflags unitbuf;static const fmtflags uppercase;static const fmtflags adjustfield;static const fmtflags basefield;static const fmtflags floatfield;typedef T2 iostate;static const iostate badbit;static const iostate eofbit;static const iostate failbit;static const iostate goodbit;typedef T3 openmode;static const openmode app;static const openmode ate;static const openmode binary;static const openmode in;static const openmode out;static const openmode trunc;typedef T4 seekdir;static const seekdir beg;static const seekdir cur;static const seekdir end;
原创粉丝点击