Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_ios<CharT,Traits>::rdbuf

      From cppreference.com
      <cpp‎ |io‎ |basic ios
       
       
       
       
      std::basic_streambuf<CharT, Traits>* rdbuf()const;
      (1)
      std::basic_streambuf<CharT, Traits>* rdbuf(std::basic_streambuf<CharT, Traits>* sb);
      (2)

      Manages the associated stream buffer.

      1) Returns the associated stream buffer. If there is no associated stream buffer, returns a null pointer.
      2) Sets the associated stream buffer tosb. The error state is cleared by callingclear(). Returns the associated stream buffer before the operation. If there is no associated stream buffer, returns a null pointer.

      Contents

      [edit]Parameters

      sb - Stream buffer to associate to.

      [edit]Return value

      The associated stream buffer, or a null pointer if there was no associated stream buffer.

      [edit]Exceptions

      May throw implementation-defined exceptions.

      [edit]Example

      Run this code
      #include <iostream>#include <sstream> int main(){std::ostringstream local;auto cout_buff=std::cout.rdbuf();// save pointer to std::cout buffer std::cout.rdbuf(local.rdbuf());// substitute internal std::cout buffer with// buffer of 'local' object // now std::cout work with 'local' buffer// you don't see this messagestd::cout<<"some message"; // go back to old bufferstd::cout.rdbuf(cout_buff); // you will see this messagestd::cout<<"back to default buffer\n"; // print 'local' contentstd::cout<<"local content: "<< local.str()<<"\n";}

      Output:

      back to default bufferlocal content: some message

      [edit]See also

      replaces therdbuf without clearing its error state
      (protected member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_ios/rdbuf&oldid=180013"

      [8]ページ先頭

      ©2009-2025 Movatter.jp