Implementing std::basic_streambuf subclass for manipulating input

梦想的初衷 提交于 2019-12-06 10:25:38

underflow() has post-conditions that you failed to establish: by the time you return from it, you need to have a get area in your streambuf that holds that character you're returning.

A single-character buffer is sufficient:

    protected:
        virtual int underflow()
        {
            ch = std::tolower(m_realBuffer.sbumpc());
  +         setg(&ch, &ch, &ch+1); 
            return ch;
        }
    private:
  +     char ch; // input buffer!
        std::streambuf &m_realBuffer;
};
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!