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` 的檢視交換。
目錄 |
[edit] 引數
v | - | 要交換的檢視 |
[edit] 返回值
(無)
[edit] 複雜度
常數時間。
[edit] 示例
執行此程式碼
#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
[edit] 參閱
交換兩個物件的值 (函式模板) | |
交換兩個範圍的元素 (函式模板) | |
交換內容 ( std::basic_string<CharT,Traits,Allocator> 的公共成員函式) |