ostrshrt.cpp

来自「C标准库源代码」· C++ 代码 · 共 54 行

CPP
54
字号
/***
* ostrshrt.cpp - definitions for ostream class operator<<(short) member functions
*
*       Copyright (c) 1991-1997, Microsoft Corporation.  All rights reserved.
*
*Purpose:
*       Contains the member function definitions for ostream operator<<(short).
*
*******************************************************************************/

#include <cruntime.h>
#include <internal.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#pragma hdrstop

ostream& ostream::operator<<(short n)
{
_WINSTATIC char obuffer[8];     // assumes max int is 65535
_WINSTATIC char fmt[4] = "%hd";
_WINSTATIC 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;

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?