利用STL函数swap进行vector内的数据交换

#include   <iostream>
#include   <string>
#include   <algorithm>
#include   <vector>

using   namespace   std;

int   main(int   argc,   char*   argv[])
{
	vector <string>   vTest;

	vTest.push_back( "a ");
	vTest.push_back( "b ");
	vTest.push_back( "c ");
	vTest.push_back( "d ");

	swap(vTest[0],   vTest[3]);

	vector <string> ::iterator   pos;
	for   (pos   =   vTest.begin();   pos   !=   vTest.end();   pos++)
	{
		cout   <<   *pos   <<   endl;
	}

	return   0;
}


 

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自www.cnblogs.com/sownchz/p/10391178.html