Chinaunix首页 | 论坛 | 博客
  • 博客访问: 854943
  • 博文数量: 254
  • 博客积分: 5350
  • 博客等级: 大校
  • 技术积分: 2045
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-27 13:27
文章分类

全部博文(254)

文章存档

2015年(1)

2014年(9)

2013年(17)

2012年(30)

2011年(150)

2010年(17)

2009年(28)

2008年(2)

分类: C/C++

2011-11-29 17:16:08

  1. /* iterdemo.cpp
  2. 指针迭代器示例。指针是一种迭代器。
  3. 示例中测试过尾值的方法不能换成测试算法返回的
  4. 迭代器是否等于NULL。
  5. */
  6. #include <iostream>
  7. #include <algorithm>

  8. using namespace std;

  9. #define SIZE 100

  10. int iarray[SIZE];

  11. int main()
  12. {
  13.     iarray[20] = 50;
  14.     int * ip = find(iarray, iarray + SIZE, 50);

  15.     // if (ip != NULL) 是错误的
  16.     if (ip == iarray + SIZE)
  17.         cout << "50 not found in array" << endl;
  18.     else
  19.         cout << *ip << " found in array" << endl;
  20.     return 0;
  21. }

/* iterdemo.cpp
指针迭代器示例。指针是一种迭代器。
示例中测试过尾值的方法不能换成测试算法返回的
迭代器是否等于NULL。
*/
#include
#include

using namespace std;

#define SIZE 100

int iarray[SIZE];

int main()
{
    iarray[20] = 50;
    int * ip = find(iarray, iarray + SIZE, 50);

    // if (ip != NULL) 是错误的
    if (ip == iarray + SIZE)
        cout << "50 not found in array" << endl;
    else
        cout << *ip << " found in array" << endl;
    return 0;
}

阅读(940) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~