//一個很典型使用vector的STL程式:
#include <vector>
#include <iostream>
using namespace std;
int main() {
vector<int> ivec;
ivec.push_back(1);
ivec.push_back(2);
ivec.push_back(3);
ivec.push_back(4);
for(vector<int>::iterator iter = ivec.begin();iter != ivec.end(); ++iter){
cout << *iter << ' ' ;
}
cout<<endl;
cout<<*(ivec.end()-1)-*ivec.begin()<<endl;// -1
cout<<ivec.end()-ivec.begin()<<endl;// 元素个数
}
在图论里
for(vector<edge>::iterator it=t[fr].begin();it!=t[fr].end();++it)
{
int to=it->v;//it->v
int wi=it->w;//->
……
}