#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
vector<int>::const_iterator& getval(vector<int>::const_iterator& ibegin, vector<int>::const_iterator& iend, int val)
{
while (ibegin != iend)
{
if (*ibegin == val)
{
return ibegin;
}
++ibegin;
}
return iend;
}
vector<int>::iterator& getval(vector<int>::iterator& ibegin, vector<int>::iterator& iend, int val)
{
while (ibegin != iend)
{
if (*ibegin == val)
{
return ibegin;
}
++ibegin;
}
return iend;
}
int main()
{
vector <int> vint = {12, 32, 434, 5, 45, 45, 5, 6, 6, 567};
int val = 567;
auto i = vint.cbegin();
auto j = vint.cend();
if (getval(i, j, val)!=j)
{
cout << "get it:" << *i << endl;
}
else
{
cout << "not found :" << val << endl;
}
system("pause");
return 0;
}
C++primer第5版课后练习习题答案9.5
最新推荐文章于 2022-04-29 06:00:00 发布