Question: In this C++ code I am getting an error in Codeblocks saying range-based for loops are not allowed in C++ 98 mode in the last

In this C++ code I am getting an error in Codeblocks saying "range-based for loops are not allowed in C++ 98 mode"

in the last for loop " for (int i : selected) { "

What do i need to change to make this run? Thank you

INPUT DATA:

11 1 1 4 2 3 5 3 0 6 4 5 7 5 3 9 6 5 9 7 6 10 8 8 11 9 8 12 10 2 14 11 12 16 3 3 6 8 1 7 9 2 1 2

CODE:

#include using namespace std;

int main() { freopen("act.txt", "r", stdin); int t = 1, a, s, e, setno = 1; while (cin >> t) { vector>> p; for (int i = 0; i < t; ++i) { cin >> a >> s >> e; p.push_back(make_pair(e, make_pair(s, a))); } sort(p.begin(), p.end()); int last = 0; vector selected; selected.push_back(p[0].second.second); for (int i = 1; i < t; ++i) { if (p[i].second.first >= p[last].first) { selected.push_back(p[i].second.second); last = i; } } cout << "Set " << setno << " Number of activities selected = " << selected.size() << " "; cout << "Activities: "; for (int i : selected) { cout << i << " "; } cout << " "; setno++; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!