string::assign MemoryGarden's Blog C++博客

string::swap - huycwork的日志 - 网易博客

string::swap   

2010-04-13 18:55:53|  分类: CPPREFERENCE私房 |  标签:  |字号 订阅

swap

原型:

 #include <string>
 
void swap( string& from );

函数swap()置换当前字符串与from的元素. 此函数以常量时间(constant time)运行. 例如, 下面的代码使用swap()交换了两个字符串的值:

 string first( "This comes first" );
 string second( "And this is second" );
 first.
swap( second );
 cout << first << endl;
 cout << second << endl;

代码将产生输出:

 And this is second This comes first
原文地址:https://www.cnblogs.com/lexus/p/3028557.html