← 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?
- A.To make it faster only
- B.So it continues after the new text and never re-finds text it just inserted
- C.Because replace() moves pos backwards
- 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 →