Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_stringbuf<CharT,Traits,Allocator>::swap

      From cppreference.com
      <cpp‎ |io‎ |basic stringbuf
       
       
       
       
      void swap( basic_stringbuf& rhs);
      (since C++11)
      (until C++20)
      void swap( basic_stringbuf& rhs)noexcept(/* see below */);
      (since C++20)

      Swaps the state and the contents of*this andrhs.

      The behavior is undefined ifAllocator does not propagate on swap and the allocators of*this andother are unequal.

      (since C++11)

      Contents

      [edit]Parameters

      rhs - anotherbasic_stringbuf

      [edit]Return value

      (none)

      [edit]Exceptions

      May throw implementation-defined exceptions.

      (since C++11)
      (until C++20)
      noexcept specification:  
      noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value
      ||std::allocator_traits<Allocator>::is_always_equal::value)
      (since C++20)

      [edit]Notes

      This function is called automatically when swappingstd::stringstream objects. It is rarely necessary to call it directly.

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <sstream>#include <string> int main(){std::istringstream one("one");std::ostringstream two("two"); std::cout<<"Before swap: one = "<<std::quoted(one.str())<<", two = "<<std::quoted(two.str())<<".\n";     one.rdbuf()->swap(*two.rdbuf()); std::cout<<"After  swap: one = "<<std::quoted(one.str())<<", two = "<<std::quoted(two.str())<<".\n";}

      Output:

      Before swap: one = "one", two = "two".After  swap: one = "two", two = "one".

      [edit]See also

      constructs abasic_stringbuf object
      (public member function)[edit]
      (C++11)
      swaps two string streams
      (public member function ofstd::basic_stringstream<CharT,Traits,Allocator>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_stringbuf/swap&oldid=160458"

      [8]ページ先頭

      ©2009-2025 Movatter.jp