FILE 1: find.h
#ifndef HEAD_H_INCLUDED<br />#define HEAD_H_INCLUDED<br />#include <vector><br />using namespace std;<br />template <typename elem_type><br />const elem_type *find(const vector<elem_type> &vec,<br /> const elem_type &value)<br />{<br /> for(unsigned int ix = 0; ix < vec.size(); ++ix)<br /> {<br /> if(vec[ix] == value)<br /> {<br /> return &vec[ix];<br /> }<br /> }<br /> return 0;<br />}<br />#endif // HEAD_H_INCLUDED
FILE 2: main.cpp
#include <vector><br />#include <string><br />#include <iostream><br />#include "head.h"<br />using namespace std;<br />int main(void)<br />{<br /> const int a_size = 5;<br /> const string a_string[a_size] = {"Gold", "Wood", "Water", "Fire", "Earth"};<br /> const string tag = "Wood";<br /> const vector<string> vec(a_string, a_string + a_size);<br /> cout << *find(vec, tag) << endl;<br /> return 0;<br />}<br />