Advertisement
FaDaQ

"Велосипед"

Apr 25th, 2021
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. using namespace std;
  5.  
  6. string ReplaceAll(std::string str, const std::string& from, const std::string& to) {
  7.     size_t start_pos = 0;
  8.     while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
  9.         str.replace(start_pos, from.length(), to);
  10.         start_pos += to.length();
  11.     }
  12.     return str;
  13. }
  14.  
  15. int main() {
  16.     string S = "!ooo.!";
  17.     cout << ReplaceAll(S, "!", ".") << endl; //первый аргумент - строка
  18.                                              //второе аргумент - что искать в строке
  19.                                              //третий аргумент - на что заменять
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement