std::basic_streambuf<CharT,Traits>::setp
提供: cppreference.com
<tbody>
</tbody>
void setp( char_type* pbeg, char_type* pend ); |
||
put 領域を定義するポインタの値を設定します。 具体的には、呼び出しの後 pbase() == pbeg、 pptr() == pbeg、 epptr() == pend になります。
引数
| pbeg | - | 新しい put 領域の先頭へのポインタ |
| pend | - | 新しい put 領域の終端へのポインタ |
戻り値
(なし)
例
Run this code
#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();
}
出力:
h e l l o , NULL NULL NULL NULL
関連項目
| 入力シーケンスの先頭、次、終端ポインタの位置を再設定します (プロテクテッドメンバ関数) |