ITeye博客

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

jishublog · 2013-09-22 17:19 · Markdown

[cpp]view plaincopy

  1. #include<iostream>
  2. #include<string>
  3. #include<algorithm>
  4. #include<vector>
  5. usingnamespacestd;
  6. intmain(intargc,char*argv[])
  7. {
  8. vector<string>vTest;
  9. vTest.push_back("a");
  10. vTest.push_back("b");
  11. vTest.push_back("c");
  12. vTest.push_back("d");
  13. swap(vTest[0],vTest[3]);
  14. vector<string>::iteratorpos;
  15. for(pos=vTest.begin();pos!=vTest.end();pos++)
  16. {
  17. cout<<*pos<<endl;
  18. }
  19. return0;
  20. }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。