Reading elements for a vector until EOL
Perhaps the simplest solution is to read the input line and parse it. You are also correct it is a good idea to write a function for reading a vector.

Consider the following:

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;iterator&gt;

std::vector&lt;int&gt; read_vector()
{
    std::string line = "";
    std::getline(std::cin, line);
    std::istringstream iss(line);

    std::vector&lt;int&gt; v;

    int x = 0;
    while (iss &gt;&gt; x)
        v.push_back(x);

    return v;
}

int main()
{
    std::cout &lt;&lt; "Enter the elements of 1st vector\n";
    std::vector&lt;int&gt; v1 = read_vector();

    std::cout &lt;&lt; "Enter the elements of 2nd vector\n";
    std::vector&lt;int&gt; v2 = read_vector();

    std::cout &lt;&lt; "v1 = { ";
    for (auto e : v1)
        std::cout &lt;&lt; e &lt;&lt; " ";

    std::cout &lt;&lt; "}\nv2 = { ";
    for (auto e : v2)
        std::cout &lt;&lt; e &lt;&lt; " ";
    std::cout &lt;&lt; "}";
}


The functionality of reading a vector is now found from read_vector; quite obviously, it reads the input string (until the delimiter, which is by default an end of the line), and reads space-separated integers, pushes them to the vector, and returns it.