I know how to replace all occurrences of a character with another character in string (How to replace all occurrences of a character in string?)
But what if I want to replace all even numbers in string with given string? I am confused between replace
, replace_if
and member replace
/find
functions of basic_string
class, because signature of functions require old_val and new_val to be same type. But old_val is char, and new_val is string. Is there any effective way to do this, not using multiple loops?
e.g. if the input string is
"asjkdn3vhsjdvcn2asjnbd2vd"
and the replacement text is
"whatever"
, the result should be
"asjkdn3vhsjdvcnwhateverasjnbdwhatevervd"