title: Get Next Element in the std::list using iterator
body: <p>I am trying to get difference between consecutive elements in a std::list. I attempted the following solution but as <a href="https://stackoverflow.com/questions/2699680/stdlist-iterator-get-next-element">this</a> thread says, I need to make a copy of iterator and increment it. Not sure what it mean since adding number to iterators also result in error. what am I missing here. I am using a previous version of C++ but not C++ 11</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;list&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      std::list&lt;int&gt; myList;
      //for (int i = 10;i &lt; 15;i++)
      myList.push_back(12);
      myList.push_back(15);
      myList.push_back(18);
      myList.push_back(19);
      myList.push_back(25);
  
      for (std::list&lt;int&gt;::const_iterator itr = myList.begin();itr != myList.end();++itr)
      {
          int x = *itr;
          int y = *(itr + 1);
          int diff = std::abs(x - y);
          cout &lt;&lt; diff &lt;&lt; "\n";
      }
  
      return 0;
  }
  </code></pre>