STL function -- “begin” and “end”

 

#include <iostream>
using namespace std;

int main(){
    int arr[] = {0,1,2,3,4,5,6,7,8,9};
    int *beg = begin(arr);        //指向arr首元素地址 
    int *last = end(arr);        //指向arr尾元素的下一个位置的地址 
    
    auto n = end(arr) - begin(arr);
    cout << "There are " << n << " element(s) in the array." << endl;
    
    while(beg != last && *beg >= 0){
        cout << *beg << " ";
        beg++;
    }
    cout << endl;
        
    return 0;
}

运行结果:

 

posted @ 2017-10-02 17:15  Mocuishle007  阅读(120)  评论(0)    收藏  举报