指针作为迭代器

来源:互联网 发布:嵌入式软件测试 编辑:程序博客网 时间:2024/06/03 17:46
/// 文件功能:/// 把指针作为迭代器用于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;}
0 0
原创粉丝点击