I have a vector of a user type object and want to sort the vector by the first string variable and then by the second string variable.
class MyClass{
private:
string a;
string b;
int x;
double y;
}
I have a vector in the main code that has the data already parsed into any number of elements depending on the file.
int main(){
vector<MyClass> data;
// Code that fills the data variable. This all works and can be displayed via print function
/*CODE TO SORT BY THE FIRST STRING THEN SORT AGAIN BY THE SECOND STRING
*
* -- Sort code here --
*
*/
return 0;
}
My question is 2 fold:
1) How do you do a sort of the vector based on a variable inside that vector? The vector should be sorted based on the first string in the class (the string labeled a).
2). How would you further sort the vector so that once the first string is sorted, sort the second string so that the output may look something like this (for all intents and purposes the numbers in the second string (string b) are strings not integers):
string a: a string b: 1
string a: a string b: 2
string a: a string b: 3
string a: a string b: 4
string a: b string b: 1
string a: b string b: 2
string a: b string b: 3
string a: b string b: 4