The following two lines do the same thing in Visual Studio 2005:
myString.insert(myString.size(),1,myNewChar);
and
myString.append(1,myNewChar);
Is the first one supposed to throw an out_of_range exception or is this the correct behavior?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is correct behavior — the index you pass is the index of the position behind the point of insertion of the new characters, not before. In fact, the C++03 standard specifically says (§21.3.5.4/2):
(where
pos1is the index you’re passing andpos2 == nposin the overload you call) — note that it’s<=rather than<.