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

来源:互联网 发布:淘宝清关无法提交信息 编辑:程序博客网 时间:2024/04/30 14:15
#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 函数的第二个参数值,可以以此来判断数组的值中时候存在相应的值