【问题标题】:istringstream "get" method implementationistringstream "get" 方法实现
【发布时间】:2009-03-01 16:46:11
【问题描述】:

“方法”实现说istringstream get

int get();
Extracts a character from the stream and returns its value (casted to an integer).

我想看看它的实现。

编辑:删除了我要移植的部分

【问题讨论】:

    标签: c++ stream


    【解决方案1】:

    您会在标题<sstream> 中找到std::istringstream。但不是get() 方法。 get() 成员继承自 basic_istream<_Elem, _Traits> 模板,您可以在 header 中找到该模板。这是我安装的 VS2005 中的实现:

    int_type __CLR_OR_THIS_CALL get()
        {   // extract a metacharacter
        int_type _Meta = 0;
        ios_base::iostate _State = ios_base::goodbit;
        _Chcount = 0;
        const sentry _Ok(*this, true);
    
        if (!_Ok)
            _Meta = _Traits::eof(); // state not okay, return EOF
        else
            {   // state okay, extract a character
            _TRY_IO_BEGIN
            _Meta = _Myios::rdbuf()->sbumpc();
    
            if (_Traits::eq_int_type(_Traits::eof(), _Meta))
                _State |= ios_base::eofbit | ios_base::failbit; // end of file
            else
                ++_Chcount; // got a character, count it
            _CATCH_IO_END
            }
    
        _Myios::setstate(_State);
        return (_Meta);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-25
      • 2016-11-25
      • 1970-01-01
      • 2017-05-19
      相关资源
      最近更新 更多