Difference between revisions of "cpp/string/basic string/swap"
From cppreference.com
< cpp | string | basic string
(indentation; return 0 can be omitted) |
(caps) |
||
Line 47: | Line 47: | ||
===Complexity=== | ===Complexity=== | ||
− | + | Constant. | |
[[de:cpp/string/basic string/swap]] | [[de:cpp/string/basic string/swap]] |
Revision as of 05:09, 18 October 2013
void swap( basic_string& other ); |
||
Exchanges the contents of the string with those of other
. All iterators and references remain valid.
Contents |
Parameters
other | - | string to exchange the contents with |
Return value
(none)
Example
Run this code
#include <string> #include <iostream> int main() { std::string a = "AAA"; std::string b = "BBB"; std::cout << "before swap" << '\n'; std::cout << "a: " << a << '\n'; std::cout << "b: " << b << '\n'; a.swap(b); std::cout << "after swap" << '\n'; std::cout << "a: " << a << '\n'; std::cout << "b: " << b << '\n'; }
Output:
before swap a: AAA b: BBB after swap a: BBB b: AAA
Complexity
Constant.