title: How to store a value obtained from a vector `pop_back()` in C++?
body: <p>I'm not sure how to cast a value obtained from the <code>pop_back()</code> function of <code>vector</code>. The following is a simple code to illustrate the problem.</p>
  
  <pre><code>#include&lt;vector&gt;
  #include&lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
    vector&lt;int&gt; a,b;
    int val;
  
    a.push_back(1);
    a.push_back(2);
    a.push_back(3);
    a.push_back(4);
  
    for(int i=0; i&lt;4; i++)
    {
      val = a.pop_back();
      b.push_back(val);
    }
  
    vector&lt;int&gt;::iterator v = b.begin();
    while( v != b.end())
    {
      cout &lt;&lt; *v &lt;&lt; " ";
      v++;
    }
    return 0;
  }
  </code></pre>
  
  <p>This is the error I get.</p>
  
  <pre><code>pushback.cpp:18:9: error: assigning to 'int' from incompatible type 'void'
      val = a.pop_back();
          ^ ~~~~~~~~~~~~
  1 error generated.
  </code></pre>
  
  <p>I tried casting as well; <code>(int)a.pop_back()</code>, but it throws an error stating <code>C-style cast from 'void' to 'int' is not allowed</code>.</p>
  
  <p>May I know if there is a standard way to store the value from the <code>pop_back()</code> function?</p>