标准库函数begin和end

//begin()和end()函数我没有调用成功,还不清楚原因,也没查

//代码运行提示表示,该区域没定义此函数,可能是作用域的问题?

1.相关知识点

  1.begin()函数返回首元素的指针,

   end()函数返回数组尾元素下一位置的指针,两个函数定义域iterator头文件

2.相关联系代码

 1 #include<iostream>
 2 #include<iterator>  //该头文件中有begin,end函数 
 3 using namespace std;
 4 int main()
 5 {
 6     int a[] = {1,2,3,4,5};
 7     //int *p = a ;   //数组名称表示数组首地址 
 8     int *p = &a[0]; //指针指向的一定是地址 
 9     int *pe = &a[5];
10     int *beg = begin(a);
11     int *last = end(a);  
12     if (p == beg)
13         cout << 1 << endl; //判断函数是否指向数组首地址 
14     if (pe == last)  //判断函数是否指向数组尾后地址 
15         cout << 2 << endl;
16     system("pause");
17     return 0;
18 } 
View Code

猜你喜欢

转载自www.cnblogs.com/gjbhpu0308/p/12398115.html