- #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;
- }
利用STL函数swap进行vector内的数据交换
最新推荐文章于 2024-10-16 10:13:45 发布