|
# include <iostream>
# include <vector>
using namespace std;
vector <int>::const_iterator find_val ( vector <int>::const_iterator beg , vector <int>::const_iterator end,int value , vector <int>::size_type &occurs);
void main()
{ int i ;
vector<int>::size_type ctr;
/*vector<int> vec;
*cout << "please enter num "<<endl;
*while (cin>>i)
*{ if ( i = 0) 有朋友说 i=0 是错的,到底怎么错呢? 是因为如果输入的数字不是0就退出while循环,没有给容器添加元素? 还是语法错误呢?
* break;
* else 怎么 实现 给容器vec添加一定元素(数字)后,输入一个操作退出while循环?
* vec.push_back(i);
* }
*/
int num[] = {1, 2, 3, 8, 9, 4, 5, 8, 7, 8}
vector<int> vec (num, sizeof(num)/sizeof(num([0]));
vector<int> ::const_iterator iter;
iter = find_val ( vec.begin() ,vec.end(), 8,ctr);
cout << *iter << ctr <<endl;
}
vector <int>::const_iterator find_val ( vector <int>::const_iterator beg , vector <int>::const_iterator end,int value , vector <int>::size_type |
|