Boost C++ Libraries: Ticket #7215: string::insert returns a wrong iterator https://svn.boost.org/trac10/ticket/7215 <p> <code>iterator insert(const_iterator p, CharT c)</code> returns an iterator witch refers to a character behind the inserted character. (Boost 1.50.0, MSVC 9.0) </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;boost/container/string.hpp&gt; int main() { std::string ss("1"); boost::container::string bs("1"); std::cout &lt;&lt; *ss.insert(ss.begin(), '0') &lt;&lt; std::endl; std::cout &lt;&lt; *bs.insert(bs.begin(), '0') &lt;&lt; std::endl; return 0; } Output: 0 1 </pre><p> In boost/container/string.hpp: </p> <pre class="wiki">iterator insert(const_iterator p, CharT c) { size_type new_offset = p - this-&gt;priv_addr() + 1; this-&gt;insert(p, cvalue_iterator(c, 1), cvalue_iterator()); return this-&gt;priv_addr() + new_offset; } </pre><p> I think that "+ 1" is unnecessary. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7215 Trac 1.4.3 Ion Gaztañaga Fri, 24 Aug 2012 21:18:22 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7215#comment:1 https://svn.boost.org/trac10/ticket/7215#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Thanks for the report. Fixed in trunk t revision: 80174 </p> Ticket