Reputation: 21865
If I have : Enter(x)
And I want to place after the (
the word room2
, but without x
, then std::insert doesn't help
since if :
std::string myString = "Enter(x)";
std::string placeMe = "room2";
myString.insert(myString.find_first_of("(") + 1 , placeMe);
Then I'd get : Enter(room2x)
.
How can I place the placeMe
instead of a certain index ?
Upvotes: 0
Views: 150
Reputation: 110658
First, you probably want find
instead of find_first_of
, since you only want to match one possible substring. Second, you want the std::string::replace
function:
myString.replace(myString.find("(") + 1, 1, placeMe);
Upvotes: 3
Reputation: 615
I believe the function you are looking for is replace instead of insert.
http://www.cplusplus.com/reference/string/string/replace/
Upvotes: 6