Untitled
#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