iset.insert(ivector.begin(),ivector.end()) //复制vector元素到set中,注意这个操作会去重
string str = join(vector," "); //vector拼接成一个string
The header <algorithm> defines a collection of functions especially designed to be used on ranges of elements.
<algorithm> 包括常用的find、count、search、replace、reserve、partition、基于sorting的函数、基于比较的函数(max/min等)、堆函数(Heap)
find函数:#include <algorithm>
InputIterator find ( InputIterator first, InputIterator last, const T& value );
copy函数:#include <algorithm>
OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result );
vector resolving_res; //利用字符串流把string切分为vector
istringstream iss(outanswer);
copy(istream_iterator(iss), istream_iterator(), back_inserter(resolving_res));
int myints[]={10,20,30,40,50,60,70}; //利用copy函数copy数组to vector
vector<int> myvector;
vector<int>::iterator it;
myvector.resize(7); // allocate space for 7 elements, Resizes the vector to contain 7 elements.
copy ( myints, myints+7, myvector.begin() );
似乎下面这个也可以完成copy功能:
int myints[] = {10,20,30,5,15};
vector<int> v(myints,myints+5);
replace函数:#include <algorithm>
void replace ( ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value );
int myints[] = { 10, 20, 30, 30, 20, 10, 10, 20 };
vector<int> myvector (myints, myints+8); // 10 20 30 30 20 10 10 20
replace (myvector.begin(), myvector.end(), 20, 99); // 10 99 30 30 99 10 10 99
count函数:#include <algorithm>
count(oriPos.begin(),oriPos.end(),"mm")>1 //count适用于vector,统计vector中有多少个某元素
注意count在set中只返回0或者1;