title: How to print last element in set in C++
body: <p>I am trying to print last element of a set <code>set&lt;int&gt;s;</code> where actual last element is 9.</p>
  
  <pre><code>set&lt;int&gt;:: iterator it=s.begin();
  while(it!=s.end())
  {
      cout&lt;&lt;*it&lt;&lt;endl;
      it++;
  }
  </code></pre>
  
  <p>when i use this loop ,through this set, it shows that last element is 9 which is correct.</p>
  
  <p>but when is use this piece of code it shows last element is 4 which is incorrect.</p>
  
  <pre><code>int setint= *s.end();
  cout&lt;&lt;setint&lt;&lt;endl;
  </code></pre>
  
  <p>but when I use this code to print first element of a set ,it prints first element correctly</p>
  
  <pre><code>int setint= *s.begin();
      cout&lt;&lt;setint&lt;&lt;endl;
  </code></pre>
  
  <p>how should i fis this?</p>