请问大侠一个关于返回vector迭代器的问题
#include<iostream>#include<vector>
using namespace std;
vector<int>::iterator search(vector<int> vec,int n)
{
for(vector<int>::iterator iter=vec.begin();iter!=vec.end();iter++)
{
if(*iter==n)
{
return iter;
}
}
return NULL;
}
void main()
{
vector<int> test;
int num;
cout<<"please input the members"<<endl;
for(int i=0;i<5;i++)
{
cin>>num;
test.push_back(num);
}
cout<<"please input the num you want to search"<<endl;
cin>>num;
vector<int>::iterator temp=search(test,num);
if(!temp==NULL)
cout<<*temp;
else
cout<<"the num "<<num<<" doesn't exist"<<endl;
}
问为什么运行之后,能找到,但输出*temp却是一个未定义的值。