⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 istream.cpp

📁 pwlib源码库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        base = 0;    if (ipfx(0))    {        c=bp->sgetc();        for (i = 0; i<MAXLONGSIZ-1; buffer[i] = (char)c,c=bp->snextc(),i++)        {            if (c==EOF)			{                state |= ios::eofbit;                break;		    }            if (!i)			{                if ((c=='-') || (c=='+'))				{                    bindex++;                    continue;				}			}            if ((i==bindex) && (buffer[i-1]== '0'))			{                if (((c=='x') || (c=='X')) && ((base==0) || (base==16)))				{                    base = 16;  // simplifies matters                    fDigit = 0;                    continue;				}                else if (base==0)                {                    base = 8;				}			}            // now simply look for a digit and set fDigit if found else break            if (base==16)			{                if (!_istxdigit(c))                    break;			}            else if ((!_istdigit(c)) || ((base==8) && (c>'7')))                break;            fDigit++;		}        if (!fDigit)		{            state |= ios::failbit;            while (i--)			{                if(bp->sputbackc(buffer[i])==EOF)				{                    state |= ios::badbit;                    break;				}                else                    state &= ~(ios::eofbit);			}            i=0;		}        // buffer contains a valid number or '\0'        buffer[i] = '\0';        isfx();	}    if (i==MAXLONGSIZ)    {        state |= ios::failbit;	}    return base;}/*******************************************************************************/int     istream::getdouble(char* buffer, int buflen)   // returns length{    int c;    int i = 0;    int fDigit = 0;     // true if legal digit encountered    int fDecimal=0;     // true if '.' encountered or no longer valid    int fExp=0;         // true if 'E' or 'e' encounted    if (ipfx(0))    {        c=bp->sgetc();        for (; i<buflen; buffer[i] = c,c=bp->snextc(),i++)		{            if (c==EOF)			{                state |= ios::eofbit;                break;			}            if ((!i) || (fExp==1))			{                if ((c=='-') || (c=='+'))				{                    continue;				}			}            if ((c=='.') && (!fExp) && (!fDecimal))			{                fDecimal++;                continue;			}            if (((c=='E') || (c=='e')) && (!fExp))			{                fDecimal++;     // can't allow decimal now                fExp++;                continue;			}            if (!_istdigit(c))                break;            if (fExp)                fExp++;            else                fDigit++;		}        if (fExp==1)            // E or e with no number after it		{            if (bp->sputbackc(buffer[i])!=EOF)			{                i--;                state &= ~(ios::eofbit);			}            else			{                state |= ios::failbit;			}		}        if ((!fDigit) || (i==buflen))            state |= ios::failbit;        // buffer contains a valid number or '\0'        buffer[i] = '\0';        isfx();	}    return i;}/*******************************************************************************/istream& istream::operator>>(char& c){    int tchar;    if (ipfx(0))        {        tchar=bp->sbumpc();        if (tchar==EOF)            {            state |= ios::eofbit|ios::badbit;            }        else            {            c = (char)tchar;            }        isfx();        }    return *this;}/*******************************************************************************/istream& istream::operator>>(short& n){	char ibuffer[MAXLONGSIZ];    long value;    char** endptr = (char**)NULL;    if (ipfx(0))    {        value = strtol(ibuffer, endptr, getint(ibuffer));        if (value>SHRT_MAX)		{            n = SHRT_MAX;            state |= ios::failbit;		}        else if (value<SHRT_MIN)		{            n = SHRT_MIN;            state |= ios::failbit;		}        else            n = (short) value;        isfx();	}	return *this;}/*******************************************************************************/istream& istream::operator>>(unsigned short& n){		char ibuffer[MAXLONGSIZ];    unsigned long value;    char** endptr = (char**)NULL;    if (ipfx(0))    {        value = strtoul(ibuffer, endptr, getint(ibuffer));        if ((value>USHRT_MAX) && (value<=(ULONG_MAX-(-SHRT_MIN))))        {			n = USHRT_MAX;			state |= ios::failbit;        }        else            n = (unsigned short) value;        isfx();	}	return *this;}/*******************************************************************************/istream& istream::operator>>(int& n){	char ibuffer[MAXLONGSIZ];    long value;    char ** endptr = (char**)NULL;    if (ipfx(0))	{        value = strtoul(ibuffer, endptr, getint(ibuffer));        if (value>INT_MAX)		{            n = INT_MAX;            state |= ios::failbit;		}        else if (value<INT_MIN)        {            n = INT_MIN;            state |= ios::failbit;        }        else            n = (int) value;        isfx();	}	return *this;}/*******************************************************************************/istream& istream::operator>>(unsigned int& n){	char ibuffer[MAXLONGSIZ];    unsigned long value;    char ** endptr = (char**)NULL;    if (ipfx(0)) 	{        value = strtoul(ibuffer, endptr, getint(ibuffer));        if ((value>UINT_MAX) && (value<=(ULONG_MAX-(unsigned long)(-INT_MIN))))		{            n = UINT_MAX;            state |= ios::failbit;		}        else            n = (unsigned int) value;        isfx();	}	return *this;}/*******************************************************************************/istream& istream::operator>>(long& n){	char ibuffer[MAXLONGSIZ];    char ** endptr = (char**)NULL;    if (ipfx(0)) 	{        n = strtoul(ibuffer, endptr, getint(ibuffer));        isfx();    }	return *this;}/*******************************************************************************/istream& istream::operator>>(unsigned long& n){	char ibuffer[MAXLONGSIZ];    char ** endptr = (char**)NULL;    if (ipfx(0)) 	{        n = strtoul(ibuffer, endptr, getint(ibuffer));        isfx();	}	return *this;}/*******************************************************************************/istream& istream::operator>>(float& n){	char ibuffer[MAXFLTSIZ];    double d;    char ** endptr = (char**)NULL;    if (ipfx(0))	{        if (getdouble(ibuffer, MAXFLTSIZ)>0)        {            d = strtod(ibuffer, endptr);            if (d > FLT_MAX)                n = FLT_MAX;            else if (d < -FLT_MAX)                n =  -FLT_MAX;            else if ((d>0) && (d< FLT_MIN))                n = FLT_MIN;            else if ((d<0) && (d> -FLT_MIN))                n = - FLT_MIN;            else                n = (float) d;		}        isfx();	}	return *this;}/*******************************************************************************/istream& istream::operator>>(double& n){	char ibuffer[MAXDBLSIZ];    char ** endptr = (char**)NULL;    if (ipfx(0))	{        if (getdouble(ibuffer, MAXDBLSIZ)>0)		{            n = strtod(ibuffer, endptr);		}        isfx();	}	return *this;}/*******************************************************************************/istream& istream::operator>>(long double& n){	char ibuffer[MAXLDBLSIZ];    char** endptr = (char**)NULL;    if (ipfx(0))	{        if (getdouble(ibuffer, MAXLDBLSIZ)>0)		{            n = (long double)strtod(ibuffer, endptr);		}        isfx();	}	return *this;}/*******************************************************************************/istream_withassign::istream_withassign(): istream(){}/*******************************************************************************/istream_withassign::istream_withassign(streambuf* _is): istream(_is){}/*******************************************************************************/istream_withassign::~istream_withassign(){}

⌨️ 快捷键说明

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