std::basic_string_view<CharT,Traits>::swap
来自 cppreference.com
< cpp | string | basic string view
constexpr void 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 << "Before swap:\n" "a = " << a << "\n" "b = " << b << "\n\n"; a.swap(b); std::cout << "After swap:\n" "a = " << a << "\n" "b = " << b << '\n'; }
输出
Before swap: a = AAA b = BBBB After swap: a = BBBB b = AAA
[编辑] 参见
交换两个对象的的值 (函数模板) | |
交换两个元素范围 (函数模板) | |
交换内容 ( std::basic_string<CharT,Traits,Allocator> 的公有成员函数) |