首页 > 学院 > 开发设计 > 正文

指针作为迭代器

2019-11-08 02:34:05
字体:
来源:转载
供稿:网友
/// 文件功能:/// 把指针作为迭代器用于STL的find( )算法,来搜索普通的数组#include <iostream>#include <algorithm>using namespace std;#define SIZE 100int iarray[SIZE];int main( ){ iarray[20] = 50; int* ip = find( iarray, iarray + SIZE, 50 ); if ( ip == iarray + SIZE ) { cout << ip << endl; // 显示迭代器当前存储的地址值 cout << iarray << endl; // 显示容器首部迭代器的地址值 cout << "50 not found in array" << endl; } else { cout << ip << endl; // 显示迭代器当前存储的地址值 cout << iarray << endl; // 显示容器首部迭代器的地址值 cout << *ip << " found in array" << endl; } return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表