定义容器类迭代器的方法:
容器类名::iterator 变量名
或者:容器类名::const_iterator 变量名
访问迭代器指向的元素:*i
批注:
stack/queue/priority_queue均不支持迭代器
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> bns;
bns.push_back(1);
bns.push_back(2);
bns.push_back(5);
bns.push_back(9);
vector<int>::const_iterator i;
for(i=bns.begin();i!=bns.end();i++)
cout<<*i<<" ";
cout<<endl;
return 0;
}