Strings. help me please :)

Hello. I have a little problem with writing algorithm.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#include <iostream>
#include <string>
using namespace std;
int main()
{

    string n;
    getline(cin, n);
    for (int i=0; i<n.size();i++){
    
        if (n[i]=='b'){
        
            // here I should write something which helps me replace every 'b' with 'c' how can I do that? I have just started c++ so I have some problems.
        }
    
    }
   
}


#include <iostream>
#include <string>
using namespace std;
int main()
{

string n;
getline(cin, n);
for (int i=0; i<n.size();i++){

if (n[i]=='b'){

n[i]='c';

}

cout<<n[i];
}


}
Topic archived. No new replies allowed.