《essential c++》 p75
template<typename IteratorType, typename elemType>
IteratorType
find(IteratorType first, IteratorType last, const elemType &value)
{
for (; first != last; ++first)
if (value == *first)
return first;
return last;
}
int main()
{
const int asize = 8;
int ia[asize] = { 1,1,2,3,5,8,13,21 };
vector<int> ivec(ia, ia + asize);
list<int> ilist(ia, ia + asize);
int *pia = find(ia, ia + asize, 1024);
if (pia != ia + asize)
cout << "0000" << endl;
//vector<int>::iterator it;
//it = find(ivec.begin(), ivec.end(), 1024);
}
在main中使用find总会报多个重载函数冲突。
我感觉应该没有问题,不知道怎么就是编译通不过。
在 std
中也有个函数叫做 find()
,编译器不知道是哪一个了。
解决方案就是去掉开头的
using namespace std;
然后更改你的输入输出语句:
cout
改为 std::cout
cin
改为 std::cin
endl
改为 std::cin