C++ STL : Reading Elements from Vector until EOL

/* In this program we are entering elements in two vector. We can enter elements if we are pressing "space key".
 If we press "Enter" then we will start to enter in new vector
*/
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
using namespace std;
std::vector<int> read_vector()
{
    std::string line = "";
    std::getline(std::cin, line);
    std::istringstream iss(line);

    std::vector<int> v;


    int x = 0;

    while (iss >> x)
        v.push_back(x);

    return v;

}

int main()

{
   
std::cout << "Enter the elements of 1st vector\n";
    std::vector<int> v1 = read_vector();

    std::cout << "Enter the elements of 2nd vector\n";

    std::vector<int> v2 = read_vector();

    std::cout << "v1 = { ";

   for(int i=0;i<v1.size();i++){
    cout<<v1[i]<<" ";
   }
    //for (auto e : v1)
      //  std::cout << e << " ";

    std::cout << "}\nv2 = { ";

    for(int i=0;i<v2.size();i++){
    cout<<v2[i]<<" ";
   }
   // for (auto e : v2)
    //    std::cout << e << " ";
    std::cout << "}";
    return 0;
}
Full question
Use of 'auto' keyword
stringstream

You may also like:
C++: Implementation of Quicksort
C++: Check if the String is Palindrome
C++: Merge_Sort using Vector
How do I learn competitive programming as a beginner?
How do I learn data structures and algorithms from scratch?

Popular Posts

Top 10 Web Sites Every Programmer Should Visit Daily

How do I improve my logical thinking and problem solving skills?

C++: STL Iterators