c++ - istringstream "get"方法实现

标签 c++ stream

“方法”实现说 istringstream get

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

我想看看它的实现。

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

最佳答案

你会发现std::istringstream在标题中 <sstream> .但不是 get()方法。 get()成员继承自 basic_istream<_Elem, _Traits>您可以在标题中找到的模板。这是我的 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);
    }

关于c++ - istringstream "get"方法实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/600077/

相关文章:

c++ - 打印链表 - C++

c++ - 如何从函数传递 QStandardItemModel?

c++ - 将 System::Byte 的交错数组转换为无符号字符**

java - For 循环替换 : For Loops to Filters

C# gif 图像到 MemoryStream 并返回(丢失动画)

C++)为什么 const int*& 参数不能采用 int* 参数?

c++ streaming io/Design a stringstream+custom streambuf 或在 char 数组上使用 mem 工具?

c++ - 如何关闭IStream?

java - 具有独立消费者的单个 InputStream 的并发处理

c++ - 我什么时候应该在 C++ 中使用我自己的销毁函数?