#include #include //#include using namespace std; template void display(const vector& vec, ostream& os=cout) { //const_iterator ÇôíÁË // ±àÒë´íÎóneed 'typename' before *** because *** is a dependent scope; https://blog.csdn.net/pb1995/article/details/49532285/ typename vector::const_iterator it = vec.begin(); typename vector::const_iterator it_end = vec.end(); for (; it != it_end; ++it) { os << *it << ' '; } os << endl; } template IteratorType myfind(IteratorType first, IteratorType last, const elemType& value) { for (; first != last; ++first) { if (value == *first) return first; } return last; } /* template void display_vector(const vector& vec, ostream& os = cout, int len = 8) { typename vector::const_iterator iter = vec.begin(), end_it = vec.end(); int elem_cnt = 1; while (iter != end_it) { os << *iter++ << (!(elem_cnt++ % len) ? '\n' : ' '); // Ò»ÐÐ8¸ö×Ö·û´® os << endl; } } */ int main() { vector vec = { 12,3,4,5 }; display(vec); vector::iterator it; it = myfind(vec.begin(), vec.end(), 3); cout << *it << endl; return 0; }