Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- using namespace std;
- string ReplaceAll(std::string str, const std::string& from, const std::string& to) {
- size_t start_pos = 0;
- while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
- str.replace(start_pos, from.length(), to);
- start_pos += to.length();
- }
- return str;
- }
- int main() {
- string S = "!ooo.!";
- cout << ReplaceAll(S, "!", ".") << endl; //первый аргумент - строка
- //второе аргумент - что искать в строке
- //третий аргумент - на что заменять
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement