Untitled

mail@pastecode.io avatar
unknown
c_cpp
18 days ago
451 B
0
Indexable
Never
#include <iostream>
#include <string>


void replace(std::string& str, char el, char newel) {

    for (int i = 0; i < str.length(); i++) {
        if (str[i] == el) {
            str[i] = newel;
        }
    }

}


int main()
{

    std::string str;
    char el, newel;

    std::cin >> str >> el >> newel;
    replace(str, el, newel);

    for (int i = 0; i < str.length(); i++) {
        std::cout << str[i];
    }
}

Leave a Comment