首页 > 代码库 > C++之vector用法

C++之vector用法

1.插入配对

std::vector<pair<int,int> > w;

w.push_back(make_pair<int,int>(f,s) );

cout <<w[i].first << " " << w[i].second <<endl;

 

2.元素去重

std::vector<int> all;

sort(all.begin(), all.end());
std::vector<int>::iterator nown = unique(all.begin(), all.end());
all.erase(nown,all.end());

 

3.排序

sort(all.begin(), all.end());

 

C++之vector用法