#include #include //for the i/o manipulator setw ("set width") #include #include //for class vector using namespace std; int main() { vector v; //Born empty, but capable of holding doubles. for (;;) { cout << "Please input a double (or control-d when done): "; double d {0}; cin >> d; if (!cin) { //if the user typed control-d, break; //out of the for loop } v.push_back(d); //Call member function push_back belonging to v //cout << "v.size() = " << v.size() << "\n"; //cout << "capacity() = " << v.capacity() << "\n"; //doubles } cout << "\n\n"; cout << "Here are the " << v.size() << " doubles that you input:\n"; //Two ways to loop through the vector: for (int i {0}; i < v.size(); ++i) { cout << setw(2) << i << " " << setw(5) << v[i] << "\n"; } cout << "\n"; //Skip a line. for (auto value: v) { //Loop through all the doubles in v. cout << value << "\n"; //value is double because v holds doubles } return EXIT_SUCCESS; }