Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <windows.h>
- using namespace std;
- void replace(string &s, const string &search, const string &replace) {
- for (size_t pos = 0; ; pos += replace.length())
- {
- pos = s.find(search, pos);
- if (pos == string::npos) break;
- s.erase(pos, search.length());
- s.insert(pos, replace);
- }
- }
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- cout << "Введите последовательность которую нужно поместить в файл: ";
- string sec;
- getline(cin, sec);
- cout << "Введите последовательность P1: ";
- string str;
- getline(cin, str);
- cout <<endl << "Введите последовательность P2: ";
- string sub_str;
- getline(cin, sub_str);
- ofstream fout;
- fout.open("data.txt");
- fout << sec;
- fout.close();
- string line;
- ifstream finp;
- finp.open("data.txt");
- getline(finp, line);
- finp.close();
- replace(line, str, sub_str);
- fout.open("data.txt", ios::app);
- fout <<endl << line;
- fout.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement