Compute all the permutations for a given vector of integers
A cleaner solution is to trust the standard library and try to re-use the generic components already available there. Your problem is solved by std::next_permutation, so you can proceed along the lines of:

#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

int main()
{
    std::vector&lt;int&gt; v = { 1, 2, 3, 4, 5 };

    do
    {
        for (auto e : v)
            std::cout &lt;&lt; e &lt;&lt; " ";
        std::cout &lt;&lt; "\n";
    } 
    while (std::next_permutation(v.begin(), v.end()));
}




For pedagogical purposes, if you wanted to keep your current structure, you could also use standard functions there. In particular, remove_item and merge could be rewritten to:

std::vector&lt;int&gt; remove_item(const std::vector&lt;int&gt;&amp; a, int id)
{
    assert(id &gt;= 0 &amp;&amp; id &lt; a.size());

    std::vector&lt;int&gt; res(a.begin(), a.begin() + id);
    res.insert(res.end(), a.begin() + id + 1, a.end());
    return res;
}

std::vector&lt;std::vector&lt;int&gt; &gt; merge(const std::vector&lt;std::vector&lt;int&gt; &gt;&amp; a, const std::vector&lt;std::vector&lt;int&gt; &gt;&amp; b)
{
    std::vector&lt;std::vector&lt;int&gt; &gt; res(a);
    std::copy(b.begin(), b.end(), std::back_inserter(res));
    return res;
}


Whatever you do, as general comments:


Avoid writing using namespace std;.
Don't write std::endl when \n will do.
You don't need std::to_string, just print b.
You are more likely to make mistakes when you put multiple statements on the same line. So instead of writing for(...) if(...) v.push_back(x); just write

for(...)
{
   if(...)
   {
      v.push_back(x);
   }
}


This also improves readability.