There is a student structure:

struct Stud { string firstName; string secondName; int averageScore; }; 

There is a class Group:

 class Group { private: string nameGroup; vector<Stud> students; public: ... } 

Sort in main:

 vector<Group> groups; sort(groups.begin(), groups.end()); copy(groups.begin(), groups.end(), ostream_iterator<Group>(cout)); 

Overloaded the output statement:

 const string& Group::getNameGroup()const { return nameGroup; } void Group::outputStudents(ostream& out)const { copy(students.begin(), students.end(), ostream_iterator<Stud>(out, " ")); } ostream& operator <<(ostream& out, const Group& group) { out << group.getNameGroup(); group.outputStudents(out); return out; } ostream& operator <<(ostream& out, const Stud& stud) { out << "\t" << stud.firstName << "\t" << stud.secondName << "\t" << stud.averageScore<<"\n"; return out; } 

After execution, sort displays only the name of the group and refers to

 void Group::outputStudents(ostream& out)const { copy(students.begin(), students.end(), ostream_iterator<Stud>(out, " ")); } 

Writes that vector iterators are incompatible. Sorry for the trouble, maybe everything is obvious, but I'm new to C ++ and I can’t understand what the error is.

  • And yes, prior to sorting, the copy worked fine, but after no. - Alexey
  • 3
    All the code would be entirely cited, or it is better to draw an example on coliru.stacked-crooked.com so it will be easier for you to help, and even clearer .. - NewView
  • There is no comparison operator used for sorting (you have it somewhere, because without it you would not even compile). And so, in that while it is resulted, problems are not visible. The problem is something else. - AnT
  • define bool Group :: operator <(const Group &) - AR Hovsepyan

0