#include <iostream>
#include <string>
using namespace std;
signed main() {
setlocale(LC_ALL, "Rus");
string strInput, findText, replaceText;
size_t position = 0;
cout << "Введите текст:" << ends;
getline(cin, strInput);
cout << "Введите то, что надо заменить: ";
getline(cin, findText);
cout << "Введите на что меняем: ";
getline(cin, replaceText);
string strOut = strInput;
while ((position = strOut.find(findText, 0)) != string::npos)
{
strOut.replace(position, findText.size(), replaceText);
position++;
}
cout << "Изменённый текст: " << strOut << endl;
cin.get();
return 0;
}
Либо:
#include <regex>
#include <string>
#include <iostream>
using namespace std;
int main() {
setlocale(LC_ALL, "Rus");
string strInput, findText, replaceText;
cout << "Введите текст: ";
getline(cin, strInput);
cout << "Введите то, что надо заменить: ";
getline(cin, findText);
cout << "Введите на что меняем: ";
getline(cin, replaceText);
strInput = regex_replace(strInput, regex(findText), replaceText);
cout << "Изменённая строка: " << strInput;
return 0;
}
javascript:B.reduce(function(s, c, i) { return i % 2 == 0 ? s + c : 0; }, 0);