I have an array of strings string relationarray[10000][2];
taken from #include<string>. Every string at relationarray[index][0] of the array has a 4 digit number at its beginning that I'm trying to use to sort the array. The array is usually not full.
from #include<algorithm>I'm trying to use
std::sort(relationarray,relationarray + (sizeof(relationarray)/sizeof(relationarray[0])) to get eveyrthing in order. but sort puts the strings at the end of the array in favor of null positions. What am I doing wrong? I tried creating comparison function for the third argument of sort but it doesn't compile.
bool waytosort(string one, string two){
if (two.empty()){
return false;
}
int first =stoi(one.substr(0,3));
int second=stoi(two.substr(0,3));
return first<second;
}
Aucun commentaire:
Enregistrer un commentaire