Hey,
I was wondering if someone could help me out here! I am trying to sort a list of files and remove the last x ones if it exceeds a constant variable (maxbuffersize). Below you can see what I did: I tried to sort the vector based on the predicate sortOnDate(). It compiles but when I try to run the application it crashes: Debug Assertion Failed! Expression: invalid operator< ....
Can anyone explain why it crashes? Thanks in advance! dennis
const int MAXBUFFERSIZE=100;
bool sortOnDate(const std::string& a, const std::string& b){
HANDLE hFileA, hFileB;
WIN32_FIND_DATAA FileInformation;
hFileA = ::FindFirstFileA(a.c_str(), &FileInformation);
hFileB = ::FindFirstFileA(b.c_str(), &FileInformation);
FILETIME ftA, ftB;
GetFileTime(hFileA, &ftA, NULL, NULL);
GetFileTime(hFileB, &ftB, NULL, NULL);
return CompareFileTime(&ftA, &ftB);
}
//________________________________________________________________
void UpdateImageBuffer(std::vector &inFiles){
//sort them by creation date
std::sort(allFiles.begin(), allFiles.end(), sortOnDate);
//delete the oldest files that exceed the max buffer size
for(unsigned int i=0; i<(allFiles.size()-MAXBUFFERSIZE); i++)
allFiles.pop_back();
}