I'm a novice to programming completely. I'm trying to teach myself C++. I want to write code to create two vectors and read their elements from input.
vector<int> v1, v2; /*Reading vector values*/ cout << "Enter the elements of 1st vector" << endl; int ele; while (cin >> ele) v1.push_back(ele); cout << "enter the elements of 2nd vector" << endl; while (cin >> ele) v2.push_back(ele);
Though it basically does what I coded it for, I want to have some improvements.
When I input elements into a vector, I would like Enter key to mean that I'm done entering the vector, while a space key says I'm entering the next element.
How can I write a loop for vector 1 and vector 2, as the code for entering elements is the same for both the vectors? (I want to write a loop for reading the two vectors.)