一个关于迭代器和指针的问题
#include<iostream>
#include<vector>
using namespace std;
vector<int>::iterator findInt( vector<int>::iterator beg, vector<int>::iterator end, int ival)
{
while( beg != end)
{
if( *beg == ival )
break;
else
++beg;
}
return beg;
}
int main()
{
int p[] = { 1,2,3,4,5};
cout << "请输入要查找的正整数: " << endl;
int ival ;
cin >> ival ;
vector<int>::iterator it = findInt(p,p+5, ival);
if( it != (p+5))
cout << " find" << endl ;
else
cout << "not fine" << endl ;
system("pause");
return 0;
}
运行时错误是:
1.error C2664: “findInt”: 不能将参数 1 从“int [5]”转换为“std::_Vector_iterator<_Ty,_Alloc>”
2. error C2678: 二进制“!=”: 没有找到接受“std::_Vector_iterator<_Ty,_Alloc>”类型的左操作数的运算符(或没有可接受的转换)
问题:不能将指针传给迭代器吗?
以上程序中,findInt函数需要两个迭代器参数,实际传递的是指针,就会出错,为什么呢?