c++测试之使用STL find()查找数组中的元素

2014-11-24 12:01:29 · 作者: · 浏览: 0

#include
#include

using namespace std;

void main()
{
int IntValue[5] = {1,2,3,4,5};
int* Result;

Result = find(IntValue, IntValue+4, 8);
if (Result != IntValue+4)
{
cout<<"Result = "<<*Result< }else
{
cout <<"No corret result"< }

while(1);
}

测试结果:
1) 数组存在相应的值,find() 函数将返回对应值
2) 数组不存在相应值,find() 将返回find 函数的第二个参数值,可以以此来判断数组的值中时候存在相应的值


摘自 DriverMonkey的专栏