#include #include #include #include #include using namespace std; class Student{ public: string nume, prenume, grupa; string stringify(){ return nume+" "+prenume+" "+grupa; } }; bool studentCompare(const Student a, const Student b){ if(a.nume == b.nume){ if(a.prenume <= b.prenume){ return true; } else{ return false; } } else if(a.nume <= b.nume){ return true; } else{ return false; } } int main(){ ios::sync_with_stdio(false); fstream f; f.open("an.txt", ios_base::in); if(!f.is_open()){ cout<<"Error: file does not exist"; return 1; } vector v; string buff; while(f>>buff){ Student tmp; tmp.nume = buff; f>>tmp.prenume; f>>tmp.grupa; v.push_back(tmp); } f.close(); sort(v.begin(), v.end(), studentCompare); f.open("an_sort.txt", ios_base::out); for(vector::iterator it = v.begin(); it < v.end(); it++){ f<stringify(); f<<"\n"; } f.close(); return 0; }