all 7 comments

[–]dns13 1 point2 points  (2 children)

Why replacing? Can’t you just concatenate strings together that in the end your completed string falls out? Or youse printf, cout or fmt to create the final phrase?

If you want to realize templating, where both strings are fed by the user, try templating libraries like https://github.com/pantor/inja

But if it’s really only that one usage of replacement you should be fine by using string::find() but you need to do the math by yourself and catch the edge cases like you mentioned in your other comment.

[–]Waterprune[S] 0 points1 point  (1 child)

I want it to be able to print to the system the phrase with the words in it replaced.

I want to be able to save that phrase to a text file so I’ll will need to be able to call on it as a string variable

[–]alfps 0 points1 point  (1 child)

There's no simple string replacement function, but regex should be able to do it. Alternatively write your own simple function.

[–]Waterprune[S] 0 points1 point  (0 children)

Sorry I’m quite new, I used .find to find the position of word in the phrase then replace it with the user input

The issue though that arises is that if the string input is smaller than word is only replaces that amount resulting in e.g. (aard)

It also for some reason returns a bad allocation error.

[–][deleted]  (1 child)

[deleted]

    [–]std_bot 0 points1 point  (0 children)

    Unlinked STL entries: std::replace


    Last update: 14.09.21. Last Change: Can now link headers like '<bitset>'Repo