当前位置:   article > 正文

结构体vector使用总结_结构体中用vector

结构体中用vector

主要有以下几种方法

  1. vector<int> list;  
  2. list.push_back(1);  
  3. list.push_back(2);  

一、初始化构造时拷贝

  1. vector<int> tem(list);  
这种拷贝,相当于复制了一份数据,list中的数据不变。

二、assign

  1. vector<int> temlist;  
  2. temlist.assign(list.begin(), list.end());  
一样的复制了一份数据,list中的数据不变。

三、swap

  1. vector<int> temlist;  
  2. temlist.swap(list);  
将list中数据全部移到temlist中,此时list中为空了

四、insert

  1. vector<int> temlist;  
  2. vector<int> temlist2;  
  3. temlist2.push_back(2);  
  4. temlist2.push_back(2);  
  5. temlist.insert(temlist.end(), temlist2.begin(), temlist2.end());  
将temlist2中的数据,全部插入到temlist的末尾。相当于复制了一份数据


本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号