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

来自cppreference.com
 
 
 
 
constexprvoid swap( basic_string_view& v )noexcept;
(C++17 起)

交换视图与 v 的内容。

目录

[编辑]参数

v - 要与之交换的视图

[编辑]返回值

(无)

[编辑]复杂度

常数。

[编辑]示例

#include <iostream>#include <string_view>   int main(){std::string_view a ="AAA";std::string_view b ="BBBB";   std::cout<<"交换前:\n""a = "<< a <<"\n""b = "<< b <<"\n\n";   a.swap(b);   std::cout<<"交换后:\n""a = "<< a <<"\n""b = "<< b <<'\n';}

输出:

交换前: a = AAA b = BBBB   交换后: a = BBBB b = AAA

[编辑]参阅

交换两个对象的值
(函数模板)[编辑]
交换两个范围的元素
(函数模板)[编辑]
交换内容
(std::basic_string<CharT,Traits,Allocator> 的公开成员函数)[编辑]
close