#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 ints. for (;;) { cout << "Please input an int (or control-d when done): "; int i {0}; cin >> i; if (!cin) { //if the user typed control-d, break; //out of the for loop } v.push_back(i); //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() << " ints 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 ints in v. cout << value << "\n"; //value is an int because v holds ints. } return EXIT_SUCCESS; }