迭代器示例

1026阅读 0评论2011-11-29 xhb8413
分类:C/C++

  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;
}

上一篇:类的嵌套定义,使用
下一篇:va_start、va_end、va_list的使用