New course! Every coder should learn Generative AI!
Try a free lesson0
How can I make a text replacer in c++?
What I mean by that is a program that detects for example all the a's in a text I give him and replaces them with b's. How do I do that?
4 Answers
+ 7
string str = "An apple a day, keeps the doctor away";
for (int i = 0; i < str.size(); i++)
{
if(str[i] == 'a' )
str[i] = 'b' ;
}
+ 3
check those:
https://en.cppreference.com/w/cpp/algorithm/replace
https://en.cppreference.com/w/cpp/algorithm/replace_copy
examples:
std::replace:
https://code.sololearn.com/c5j0ez6an7MJ/#cpp
std::replace_copy:
https://code.sololearn.com/c3a6IVts2b9o/#cpp
+ 2
Thanks guys!