0

Possible Duplicate:
How to replace all occurrences of a character in string?

E.g, I have a string, "Hello World" and I want to replace all the "l"s with "1"s. How would I do this? I am new to c++. Most of my background is in Python in which you could just use the .replace method.

0

1 Answer 1

5

Use std::replace.

#include <string> #include <algorithm> #include <iostream> int main() { std::string str = "Hello World"; std::replace(str.begin(),str.end(),'l','1'); std::cout << str; //He11o Wor1d } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.