学习迭代器

#include <iostream>
#include <vector>
using namespace std;

vector<int>::iterator find(vector<int>& source, int num)
{
    vector<int>::iterator begen = source.begin();
 vector<int>::iterator end = source.end();
 while (begen != end)
 {
  if (*begen == num) 
   return begen;
  begen++;
 }
}

int main()
{
    vector<int> a;
 int i;
 for(i = 0; i <= 10; i++)
  a.push_back(i);
 vector<int> c(a.begin(), a.end());

 vector<int>::iterator result = find(a, 4);
 cout<<*result<<endl;

 cout<<*(a.begin())<<endl;

   
 system("pause");
 return 0;
}

posted @ 2009-02-16 11:55  谭志宇  阅读(149)  评论(0编辑  收藏  举报