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; }
运行结果:


浙公网安备 33010602011771号