I am having trouble to figure out, how to sort a vector of vector of strings, here is the testing code.
#include <iostream>
#include <vector>
#incl
I'm going to assume each vector represents an record of some type, and compare the internal strings from left to right. Obviously the sorter() code is easily replaceable. You should to add a sorter() function somewhere to your code, and pass it to the std::sort algorithm.
bool sorter(const std::vector& left, const std::vector& right)
{
//go through each column
for(int i=0; i right[i])
return true;
// if left is "less" return that we go lower
else if (left[i] < right[i])
return false;
}
// if left is longer, it goes higher
if (left.size() > right.size())
return true;
else //otherwise, left go lower
return false;
}
int main() {
std::vector > data_var;
//...
//sorting code here...
std::sort(data_var.begin(), data_var.end(), sorter);
//...
}