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/archive/2013/04/18/3028557.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/85150

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午9:54
下一篇 2023年2月9日 下午9:54

相关推荐