I want to sort a name list using std::sort. The problem is that I can only sort first name instead of firstname and last name together, the class I have create is like this:
class Name{
public:
Name(string first, string last):firstName(first), lastName(last){};
string getFirstName() const{
return firstName;
};
string getLastName() const{
return lastName;
}
private:
string firstName;
string lastName;
};
Once I get first name and last name I store them in the class Name, but I read them from a file, and the code is like this
file.open("namelist.txt");
vector<string> strvec;
while (!file.eof()){
string firstName, lastName;
file >> firstName;
file >> lastName;
Name n(firstName,lastName);
strvec.push_back(firstName);
}
As you can see I store first Name in the vector, so I can sort using
sort(strvec.begin(),strvec.end());
But I only sort the first name instead of all together, the idea of using class is that i could sort them together, my idea is using vector<Name> strvec
but I don't know how to add firstname and lastname together in the vector, does anyone have idea of doing it?