标准输入流(pubsetbuf)使用的内部缓冲区

时间:2019-05-23 21:49:30

标签: c++ istream istringstream

我正在尝试设置输入流的内部缓冲区,但是我在C ++ 17中的实现未为istringstream实现pubsetbuf()。

我尝试了其他一些技术,但是它们很慢,或者复制了原始缓冲区。我正在寻找一种不做任何复制的快速方法。

这与有关输出流的问题密切相关: Setting the internal buffer used by a standard stream (pubsetbuf)

我一直在密切关注它,但是输入流的缓冲区仍未初始化/为空。

...
<layout class="QGridLayout" name="page_4">
 <item row="0" column="0">
  <layout class="QGridLayout" name="gridLayout_8">
      ...
  </layout>
 </item>
</layout>
...

1 个答案:

答案 0 :(得分:0)

我已经解决了!找出差异。

template <typename char_type>
struct istreambuf : public std::basic_streambuf<char_type, std::char_traits<char_type> >
{
    istreambuf(char_type* buffer, std::streamsize buffer_length)
    {
        // Set the "put" pointer to the start of the buffer and record its length.
        //this->setp(buffer, buffer + buffer_length);

        // Set the "get" pointer to the start of the buffer, the next item, and record its length.
        this->setg(buffer, buffer, buffer + buffer_length);
    }
};

我需要设置“ get”指针,而不是“ put”指针。现在效果很好。

相关问题