您的位置:首页 > 编程语言 > C语言/C++

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

2012-05-28 16:00 399 查看
#include <algorithm>
#include <iostream>

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<<endl;
}else
{
cout <<"No corret result"<<endl;
}

while(1);
}

测试结果:

1) 数组存在相应的值,find() 函数将返回对应值

2) 数组不存在相应值,find() 将返回find 函数的第二个参数值,可以以此来判断数组的值中时候存在相应的值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  测试 c++ include
相关文章推荐