The signature of (pos, char) doesn't even exist. The closest is (iterator, char).

I think the problem is that insert tries to _insert_, not _replace_, and stl can't find the end of the string in order to figure out how much to shift (since there isn't a null character).

I think the only real alternative here is to do the \0 initialization in a char buffer, and then initialize a new std::string around the existing buffer (not doing a copy).

Anyway, I don't think there's value in making this code epsilon faster at the cost of making it much less clear. We're not processing a ton of data here.