vector遍历
vector的遍历一般使用迭代器
vector的遍历一般使用迭代器
int arr[]={1,2,3,4........};
vector< int > ivec(begin(arr),end(arr));
for(auto it=ivec.begin();it!= ivec.end();++it)
- 1
或者采用
int arr[]={1,2,3,4........};
vector< int > ivec(begin(arr),end(arr));
vector<int>::iterator it;
还可以for_each来遍历vector形式,如下:
int arr[]={1,2,3,4........};
vector< int > ivec(begin(arr),end(arr));
for_each(ivec.begin(),ivec.end(),printf);
它还可以像数组一样去遍历
int arr[]={1,2,3,4};
vector< int > ivec(begin(arr),end(arr));
for(decltype(ivec.size()) i=0;i<4;++i)
std::unordered_map 无序哈希
unordered_map<Key,T>::iterator it;
(*it).first; // the key value (of type Key)
(*it).second; // the mapped value (of type T)
(*it); // the "element value" (of type pair<const Key,T>)