首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_streambuf::setp

void setp( char_type* pbeg, char_type* pend );

?

?

设置定义PUT区域的指针的值。特别是在电话之后pbase() == pbeg,,,pptr() == pbeg,,,epptr() == pend...

参数

pbeg

-

pointer to the new beginning of the put area

pend

-

pointer to the new end of the put area

返回值

%280%29

二次

代码语言:javascript
复制
#include <iostream>
#include <array>
 
// Buffer for std::ostream implemented by std::array
template<std::size_t SIZE, class CharT = char>
class ArrayedStreamBuffer : public std::basic_streambuf<CharT>
{
public:
    using Base = std::basic_streambuf<CharT>;
    using char_type = typename Base::char_type;
 
    ArrayedStreamBuffer() : buffer_{} // value-initialize buffer_ to all zeroes
    {
        Base::setp(buffer_.begin(), buffer_.end()); // set std::basic_streambuf
            // put area pointers to work with 'buffer_'
    }
 
    void print_buffer()
    {
        for (const auto& i: buffer_) {
            if (i == 0) {
                std::cout << "NULL";
            } else {
                std::cout << i;
            }
            std::cout << " ";
        }
        std::cout << "\n";
    }
 
private:
    std::array<char_type, SIZE> buffer_;
};
 
int main()
{
    ArrayedStreamBuffer<10> streambuf;
    std::ostream stream(&streambuf);
 
    stream << "hello";
    stream << ",";
 
    streambuf.print_buffer();
}

二次

产出:

二次

代码语言:javascript
复制
h e l l o , NULL NULL NULL NULL

二次

另见

setg

repositions the beginning, next, and end pointers of the input sequence (protected member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com