0

I am getting an invalid argument error (C++) in Eclipse version when trying to do a swap and I'm not sure how to resolve it. It seems like an IDE/config issue, here is the section of the code where I get the error:

'''

int partition(vector<Bid>& bids, int begin, int end) {
    int low = begin;
    int high = end;

    //Choose the middle element as the pivot
    int pivot = begin + (end - begin) /2;

    bool done = false;
    //While loops if not done
    while (!done) {
        //Increment low if less than pivot
        while (bids.at(low).title.compare(bids.at(pivot).title) < 0) {
            low++;
        }

        //Decrement high if less than pivot
        while (bids.at(pivot).title.compare(bids.at(high).title) < 0) {
            high--;
        }

        if (low >= high) {
            done = true;
        } else {
            //Swap low and high bids
            swap(bids.at(low), bids.at(high));
        }
    }

    return high;
}

'''

Eclipse Neon.3 Release 4.6.3

  • How do I add the -std=c++11 option? – Kali Beatty Nov 19 '21 at 23:39
  • This may help: https://stackoverflow.com/a/22001437/260313 – rturrado Nov 20 '21 at 00:11
  • 1
    If possible, update the version of Eclipse. I used to use Neon back when my tribe and I hunted Woolly Mammoths for sustenance. In modern Eclipse versions, Project-Properties. Expand the C/C++Build tree and click Settings. Select the Tool Settings tab. Expand the C++ Compiler tree and select Dialect. Pick ISO C++11 from the Language Standard drop-down. – user4581301 Nov 20 '21 at 00:38
  • Eclipse Neon is now 5 years and 15 releases old, use the current Eclipse 2021-09 – greg-449 Nov 20 '21 at 08:00
  • Thank you - I did install the latest version, was able to pick the language standard, but for some reason am still getting invalid argument on my swap. I'm using namespace std so I really don't get what the problem is... – Kali Beatty Nov 20 '21 at 19:05

0 Answers0