67)vector的begin() end() 和 front() back()的区别 rbegin() rend()

1)

··············

 

2)`````````v1.begin() 和v1.end()  是作为迭代器v1的 第一个位置  和 最后一个元素的下一个位置。

`````````````v1.front()   是v1这个动态数组的第一个元素的值  

············ v1.back()是v1的最后一个元素的值。

 

3)

    

 

 4)正向和反向的使用rbegin和begin()

    

 1 #include<iostream>
 2 #include<vector>
 3 
 4 using namespace std;
 5  void hanshu()
 6  {
 7      vector<int> v1;
 8      v1.push_back(2);
 9      v1.push_back(3);
10      v1.push_back(4);
11     //正向遍历
12      for(vector<int>::iterator it=v1.begin();it!=v1.end();it++)
13      {
14         cout<<*it<<endl;
15      }
16      cout<<"开始反向输出这个动态数组了"<<endl;
17      //反向遍历
18      for(vector<int>::reverse_iterator rit=v1.rbegin();rit!=v1.rend();rit++)
19      {
20         cout<<*rit<<endl;
21      }
22 
23 
24  }
25  int main()
26  {
27     hanshu();
28      return 0;
29  }

 

    结果展示:


    

 

posted @ 2018-01-14 16:14  小油菜1  阅读(1148)  评论(0编辑  收藏  举报