I'm an absolute beginner working through Stroustrup's 'Programming Principles and Practice' book.
In chapter 4 it introduced the End Of File input; Ctrl-D that worked on previous code snippets. The code I'm now working on is this simple vector example.
I believe Ctrl-D should exit the range-for loop and then cout the calculations, however this isn't working. I can only exit the program, and see no results, via Ctrl-Z (stopped), Ctrl-C or the | (pipe) symbol, anything else just continues the input loop.
I am on linux using a terminal emulator (terminator) to write, run and compile. I have tried the same code in Code::Blocks and the output is exactly the same.
Please; how can I break out of the input loop?
#include "std_lib_facilities.h" //provided PPP header file
int main()
{
vector<double>temps;
for (double temp; cin >> temp;) //get stuck in here
temps.push_back(temp);
double sum=0; //want to get to here
for (double x : temps) sum += x;
cout << "Average temperature: " << sum/temps.size() << endl;
sort(temps.begin(),temps.end());
cout << "Median temperature: " << temps[temps.size()/2] << endl;
}