I am currently attempting to use std::sort() in C++ to sort a vector of const char* vectors. Here is my current code:
std::vector<std::vector<const char*>> PlayerManager::GetSortedHighscores()
{
std::vector<std::vector<const char*>> sortedHighscores;
std::fstream hsFileIStream;
hsFileIStream.open("Highscores.csv", std::ios::in);
if (hsFileIStream.fail())
{
return sortedHighscores;
}
std::string line;
while (std::getline(hsFileIStream, line))
{
std::vector<const char*> lineV;
std::stringstream s(line);
std::string data;
while (std::getline(s, data, ','))
{
lineV.push_back(data.c_str());
}
sortedHighscores.push_back(lineV);
}
std::sort(sortedHighscores.begin(), sortedHighscores.end(), CompareRecord);
return sortedHighscores;
}
bool PlayerManager::CompareRecord(std::vector<const char*>& record1, std::vector<const char*>& record2)
{
const int MOVE_INDEX = 3;
return (record1[MOVE_INDEX] < record2[MOVE_INDEX]);
}
However I am receiving the following errors:
'PlayerManager::CompareRecord': non-standard syntax; use '&' to create a pointer to member
'std::sort': no matching overloaded function found
'void std::sort(const _RanIt,const _RanIt)': expects 2 arguments - 3 provided
If anyone can assist it would be much appreciated.