示例#1
0
ostream& ostream::operator<<(unsigned int n)
{
    char obuffer[12];
    char fmt[4] = "%u";
    char leader[4] = "\0\0";
    if (opfx()) 
	{
        if (n)
		{
            if (x_flags & (hex|oct))
			{
                if (x_flags & hex)
				{
                    if (x_flags & uppercase)
                        fmt[1] = 'X';
                    else
                        fmt[1] = 'x';
                    leader[1] = fmt[1];   // 0x or 0X  (or \0X)
				}
                else
                    fmt[1] = 'o';
                if (x_flags & showbase)
                    leader[0] = '0';
			}
            else if (x_flags & showpos)
			{
                leader[0] = '+';
			}
		}
        sprintf(obuffer,fmt,n);
        writepad(leader,obuffer);
        osfx();
    }
    return *this;
}
示例#2
0
ostream& ostream::operator<<(short n)
{
    char obuffer[8];     // assumes max int is 65535
    char fmt[4] = "%hd";
    char leader[4] = "\0\0";
    if (opfx()) 
	{
        if (n)
		{
            if (x_flags & (hex|oct))
			{
                if (x_flags & hex)
				{
                    if (x_flags & uppercase)
                        fmt[2] = 'X';
                    else
                        fmt[2] = 'x';
                    leader[1] = fmt[2];   // 0x or 0X  (or \0X)
				}
                else
                    fmt[2] = 'o';
                if (x_flags & showbase)
                    leader[0] = '0';
			}
            else if ((n>0) && (x_flags & showpos))
			{
                leader[0] = '+';
			}
		}
        sprintf(obuffer,fmt,n);
        writepad(leader,obuffer);
        osfx();
    }
    return *this;
}
ostream& ostream::operator<<(long double f)
{
_WINSTATIC char obuffer[28];
_WINSTATIC char fmt[12];
_WINSTATIC char leader[4];
    char * optr = obuffer;
    int x = 0;
    unsigned int curprecision = __min((unsigned)x_precision,LDBL_DIG);
    if (opfx()) {
        if (x_flags & ios::showpos)
            leader[x++] = '+';
        if (x_flags & ios::showpoint)
            leader[x++] = '#';  // show decimal and trailing zeros
        leader[x] = '\0';
        x = sprintf(fmt,"%%%s.%.0uLg",leader,curprecision) - 1;
        if ((x_flags & ios::floatfield)==ios::fixed)
            fmt[x] = 'f';
        else
            {
            if ((x_flags & ios::floatfield)==ios::scientific)
                fmt[x] = 'e';
            if (x_flags & uppercase)
                fmt[x] = (char)toupper(fmt[x]);
            }

        sprintf(optr,fmt,f);
        x = 0;
        if (*optr=='+' || *optr=='-')
            leader[x++] = *(optr++);
        leader[x] = '\0';
        writepad(leader,optr);
        osfx();
        }
    return *this;
}
示例#4
0
ostream& ostream::operator<<(const char * s)
{
    if (opfx()) 
	{
        writepad("",s);
        osfx();
    }
    return *this;
}
示例#5
0
ostream& ostream::operator<<(const void * ptr)
{
    char obuffer[12];
    char fmt[4] = "%p";
    char leader[4] = "0x";
    if (opfx())
	{
        if (ptr)
		{
            if (x_flags & uppercase)
                leader[1] = 'X';
		}
        sprintf(obuffer,fmt,ptr);
        writepad(leader,obuffer);
        osfx();
	}
    return *this;
}
示例#6
0
ostream& ostream::operator<<(double f)
{
    char obuffer[24];
    char fmt[8];
    char leader[4];
    char * optr = obuffer;
    int x = 0;

    // x_floatused nonzero indicates called for float, not double
    unsigned int curprecision = (x_floatused) ? FLT_DIG : DBL_DIG;
    x_floatused = 0;    // reset for next call

    curprecision = __min((unsigned)x_precision,curprecision);

    if (opfx()) 
	{
        if (x_flags & ios::showpos)
            leader[x++] = '+';
        if (x_flags & ios::showpoint)
            leader[x++] = '#';  // show decimal and trailing zeros
        leader[x] = '\0';
        x = sprintf(fmt,"%%%s.%.0ug",leader,curprecision) - 1;
        if ((x_flags & ios::floatfield)==ios::fixed)
            fmt[x] = 'f';
        else
		{
            if ((x_flags & ios::floatfield)==ios::scientific)
                fmt[x] = 'e';
            if (x_flags & uppercase)
                fmt[x] = (char)toupper(fmt[x]);
		}

        sprintf(optr,fmt,f);
        x = 0;
        if (*optr=='+' || *optr=='-')
            leader[x++] = *(optr++);
        leader[x] = '\0';
        writepad(leader,optr);
        osfx();
	}
    return *this;
}
示例#7
0
ostream&  ostream::operator<<(unsigned char c)
{
    if (opfx())
    {
        if (x_width)
		{
                char outc[2];
            outc[0] = c;
            outc[1] = '\0';
            writepad("",outc);
		}
        else if (bp->sputc(c)==EOF)
        {
            if (bp->overflow(c)==EOF)
                state |= (badbit|failbit);  // fatal error?
		}
        osfx();
    }
    return *this;
}