I am creating a program in C++ that utilizes the sort and unique functions to sort a vector array and get rid of duplicates. Here is my code:
// Sort tokens that need to be sorted for output
auto numsEqual = [](const LexItem& element1, const LexItem& element2)
{
return stod(element1.GetLexeme()) == stod(element2.GetLexeme());
};
auto stringsEqual = [](const LexItem& element1, const LexItem& element2)
{
return element1.GetLexeme() == element2.GetLexeme();
};
sort(nconsts.begin(), nconsts.end(), compareNconsts);
nconsts.erase( unique( nconsts.begin(), nconsts.end(), numsEqual ), nconsts.end() );
sort(idents.begin(), idents.end(), compareStrings);
idents.erase(unique(idents.begin(), idents.end(), stringsEqual ), idents.end() );
sort(sconsts.begin(), sconsts.end(), compareStrings);
sconsts.erase(unique(sconsts.begin(), sconsts.end(), stringsEqual ), sconsts.end() );
sort(bconsts.begin(), bconsts.end(), compareStrings);
// sconsts.erase(unique(sconsts.begin(), sconsts.end(), stringsEqual ), sconsts.end() );
The problem is, when I output the array it appears that it has not been sorted at all, and duplicates have not been removed either. It works in clion in my windows system, but when I paste it into linux (vocareum auto grader) it doesn't pass any test cases because the output is not sorted and there are duplicates. I am new to c++ and have been trying to debug this but debugging within vocareum is very hard, can anybody help? I am willing to paste more code if needed, just lmk
These are my imports btw
#include <iostream>
#include <sstream>
#include <cstring>
#include <regex>
#include <string>
#include <fstream>
#include <map>
#include <algorithm>
#include <map>
#include "lex.h"
using namespace std;