• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <streambuf>

    std::basic_streambuf::operator=

    namespace std {
      template<class CharT, class Traits = char_traits<CharT>>
      class basic_streambuf {
      protected:
        basic_streambuf& operator=(const basic_streambuf& rhs);
    
        ……
      };
    }
    

    概要

    入力部分列ポインタ、出力部分列ポインタ、ロケールをコピーする。

    事後条件

    戻り値

    *this。

    #include <iostream>
    #include <streambuf>
    
    // streambufを継承したクラス
    class dummy_buf : public std::streambuf {
        char space_[10] = {'A', 'B', 'C'};
    public:
        dummy_buf(void) {
            // 入力列に配列を設定
            setg(space_, space_, space_ + 10);
        }
        void copy(const dummy_buf& rhs) {
            // ベースクラスのoperator=を呼ぶ
            std::streambuf::operator=(rhs);
        }
    };
    
    int main(void) {
        dummy_buf buf1{};
        dummy_buf buf2{};
        std::cout << char(buf1.sbumpc()) << std::endl;
        buf2.copy(buf1);
        std::cout << char(buf2.sbumpc()) << std::endl;
    }
    

    出力

    A
    B
    

    バージョン

    言語

    • C++98

    参照