🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Strings in C++: all 10 questions

Quiz: Strings in C++ · Question 8 of 10

Why does the replace-all loop add pos += to.size() after each replacement?

Why does the replace-all loop add pos += to.size() after each replacement?

  1. A.To make it faster only
  2. B.So it continues after the new text and never re-finds text it just inserted
  3. C.Because replace() moves pos backwards
  4. D.It is not needed
Answer & explanation

Correct answer: So it continues after the new text and never re-finds text it just inserted

For "a" → "aa", skipping it would make the loop run forever.

Can you get the rest right without peeking?

Take the timed Quiz: Strings in C++ quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →