I am pretty much new in C++. I started with "Programming principles and practice using C++" book. It has been great so far but I have problem with some of the commands compilation. I wrote a simple code as follows:
int main()
{
vector<double> temps;
for (double temp; cin >> temp;) {
temps.push_back(temp);
}
double sum = 0;
for (int x:temps) sum += x;
cout << "\nAverage temperature is: " << sum / temps.size() << endl;
sort(temps);
cout << "Median temperature is: " << temps[temps.size()/2] << endl;
}
Unfortunately, I am receiving compilation error on the for-loop as: error: range-based 'for' loops are not allowed in C++98 mode
.
I have downloaded the newest version of CodeBlocks with new GCC compiler, but still gives me the same error. I have also tried other compilers in CodeBlocks but they didn't resolve the issue.
I had the same experience with "constexpre" command as well which I could not resolve it. By the way, examples and exercises of the book sometimes need a ".h" file which I have it on the folder which the this file sits. Any advise?