#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++示例展示了如何使用STL中的find函数来搜索数组中的特定值。当数组中存在该值时,find函数将返回对应的指针;若不存在,则返回指向数组尾部的指针,可用于判断值是否存在于数组中。
964

被折叠的 条评论
为什么被折叠?



