- /* iterdemo.cpp
-
指针迭代器示例。指针是一种迭代器。
-
示例中测试过尾值的方法不能换成测试算法返回的
-
迭代器是否等于NULL。
-
*/
-
#include <iostream>
-
#include <algorithm>
-
-
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;
- }
/* 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;
}