title: std::list iterator: get next element
body: <p>I'm trying to build a string using data elements stored in a std::list, where I want commas placed only between the elements (ie, if elements are {A,B,C,D} in list, result string should be "A,B,C,D".</p>
  
  <p>This code does not work:</p>
  
  <pre><code>typedef std::list&lt; shared_ptr&lt;EventDataItem&gt; &gt; DataItemList;
  // ...
  std::string Compose(DataItemList&amp; dilList)
  {
      std::stringstream ssDataSegment;
      for(iterItems = dilList.begin();
          iterItems != dilList.end(); 
          iterItems++)
      {
          // Lookahead in list to see if next element is end
          if((iterItems + 1) == dilList.end())  
          {
              ssDataSegment &lt;&lt; (*iterItems)-&gt;ToString();
          }
          else
          {
              ssDataSegment &lt;&lt; (*iterItems)-&gt;ToString() &lt;&lt; ",";
          }
      }
      return ssDataSegment.str();
  }
  </code></pre>
  
  <p><strong>How do I get at "the-next-item" in a std::list using an iterator?  I would expect that it's a linked-list, why can't I get at the next item?</strong></p>