Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_string_view<CharT,Traits>::swap

      From cppreference.com
      <cpp‎ |string‎ |basic string view
       
       
       
      std::basic_string_view
       
      constexprvoid swap( basic_string_view& v)noexcept;
      (since C++17)

      Exchanges the view with that ofv.

      Contents

      [edit]Parameters

      v - view to swap with

      [edit]Return value

      (none)

      [edit]Complexity

      Constant.

      [edit]Example

      Run this code
      #include <iostream>#include <string_view> int main(){std::string_view a="AAA";std::string_view b="BBBB"; std::cout<<"Before swap:\n""a = "<< a<<"\n""b = "<< b<<"\n\n";     a.swap(b); std::cout<<"After swap:\n""a = "<< a<<"\n""b = "<< b<<'\n';}

      Output:

      Before swap:a = AAAb = BBBB After swap:a = BBBBb = AAA

      [edit]See also

      swaps the values of two objects
      (function template)[edit]
      swaps two ranges of elements
      (function template)[edit]
      swaps the contents
      (public member function ofstd::basic_string<CharT,Traits,Allocator>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/basic_string_view/swap&oldid=152801"

      [8]ページ先頭

      ©2009-2025 Movatter.jp