I have a header file called StudentRecord.cpp which declares the function:

vector<Student>::iterator find (const string& studentName);

In my Student Record.cpp file i have written the folloing code:

vector<Student>::iterator StudentRecord::find(const string& studentName){
   vector<Student>::iterator find;
   for(find = students.begin(); find != students.end(); find++) {
      if (students[find].getName() == studentName) {
         return students[find];
      else {
      cout << "Message: student studentName is not found " << endl;

The problem I have in with the part students[find].getName() == studentName. My compiler gives an error no match for operator[] in StudentRecord*this->StudentRecord::students[find]. Please note that Students is a vector object and i wish to find a students name. If the name is found then this function needs to return a vector::iterator type.

If anyone has any idea of how to fix the mistakes? Please Help

You can't use an iterator with the [] operator, you're supposed to use an integer index with the [] operator.

Why not just use the iterator that you've already defined. e.g. if(find->getName() == studentName){return find;