Merge sort using c++ vectors I'm still learning C++ and also algorithms. So I'm expecting to do a lot of refactoring. Here's my code

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

std::vector&lt;int&gt; mergesort(std::vector&lt;int&gt; &amp;);
std::vector&lt;int&gt; merge(std::vector&lt;int&gt; &amp;, std::vector&lt;int&gt; &amp;);
std::vector&lt;int&gt;::iterator get_midpoint(std::vector&lt;int&gt; &amp;);

int main()
{
  std::vector&lt;int&gt; vect;
  int num = 0;
  while(std::cin &gt;&gt; num)
  {
    vect.push_back(num);
  }
  std::vector&lt;int&gt; temp_vect = mergesort(vect);
  for(int num: temp_vect) {
    std::cout &lt;&lt; num  &lt;&lt; std::endl;
  }

}

std::vector&lt;int&gt; mergesort(std::vector&lt;int&gt; &amp;unsorted_vector)
{
  std::vector&lt;int&gt;::iterator middle = unsorted_vector.begin();
  std::vector&lt;int&gt; sorted_vect, first_half, second_half, first_temp, second_temp;
  if(unsorted_vector.size() == 1) {
    return unsorted_vector;
  } else {
    middle = get_midpoint(unsorted_vector);
    first_temp.insert(first_temp.begin(), unsorted_vector.begin(), middle);
    second_temp.insert(second_temp.begin(), middle, unsorted_vector.end());
    first_half = mergesort(first_temp);
    second_half = mergesort(second_temp);
    sorted_vect = merge(first_half, second_half);
    return sorted_vect;
  }
}

std::vector&lt;int&gt; merge(std::vector&lt;int&gt; &amp; first_vect, std::vector&lt;int&gt; &amp; second_vect)
{
  std::vector&lt;int&gt; sorted_vect;
  auto first_it = first_vect.begin(),
        second_it = second_vect.begin();

  while(first_it != first_vect.end() &amp;&amp; second_it != second_vect.end()) {
      if(*first_it &lt; *second_it) {
        sorted_vect.push_back(*first_it);
        first_it++;
      } else {
        sorted_vect.push_back(*second_it);
        second_it++;
      }
  }

  sorted_vect.insert(sorted_vect.end(), first_it, first_vect.end());
  sorted_vect.insert(sorted_vect.end(), second_it, second_vect.end());

  return sorted_vect;
}

std::vector&lt;int&gt;::iterator get_midpoint(std::vector&lt;int&gt; &amp;vect)
{
  std::vector&lt;int&gt;::iterator it = vect.begin();
  int middle = 0;
  if(vect.size() % 2 == 0) {
    middle =  vect.size() / 2;
  } else {
    middle = (vect.size() - 1) / 2;
  }
  std::advance(it, middle);
  return it;
}
I think you input routine is not really safe. maybe add an explicit break?

while (true) {
    cin &gt;&gt; num;
    if (cin.fail)
        break;
    vect.push_back(num);
}

What happens when unsorted_vector is empty. You check for size == 1 maybe turn that into size &lt;= 1
Stuff like this is hard to read:

std::vector&lt;int&gt; sorted_vect, first_half, second_half, first_temp, second_temp;


I would definitely suggest to put every name onto its own line and add the explicit type. Its not that you are saving trees here.
Do not use else after an early exit.

if(unsorted_vector.size() == 1) {
    return unsorted_vector;
} else {
// Stuff
}


Is equivalent to:

if(unsorted_vector.size() == 1) {
    return unsorted_vector;
}
// Stuff


However with less indentation and easier control flow.
You should definitely reserve memory in your merge function:

vector&lt;int&gt; sorted_vect;
sorted_vect.reserve(first_vect.size()+second_vect.size());

Use descriptive names. This is purely subjective, but whenever I see vect and friends i cringe. What do you really save from ommitting "or"?