This is the correct behavior - the index you pass is the position index behind the insertion point of the new characters, not earlier. In fact, the C ++ 03 standard specifically says (ยง21.3.5.4 / 2):
Required pos1 <= size()andpos2 <= str.size()
(where pos1is the index that you pass, and pos2 == nposin the overload that you call) - note that this is <=, not <.
source
share