Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <string>
- #include <iterator>
- #include <iostream>
- #include <windows.h>
- using namespace std;
- string dos(const char * s)
- {
- static char buf[BUFSIZ];
- CharToOemA(s, buf);
- return string(buf);
- }
- string win(const char * s)
- {
- static char buf[BUFSIZ];
- OemToCharA(s, buf);
- return string(buf);
- }
- int main()
- {
- string source, replace;
- ifstream ifs("1.txt");
- string inputtext(
- (istreambuf_iterator<char>(ifs))
- , istreambuf_iterator<char>());
- cout << dos("Текст с файла:\n\n") << dos(inputtext.c_str()) << endl;
- cout << dos("Что меняем?\n");
- cin >> source;
- cout << dos("На что меняем?\n");
- cin >> replace;
- replace = win(replace.c_str());
- source = win(source.c_str());
- int it = inputtext.find(source, 0);
- while (it != string::npos)
- {
- inputtext.replace(it, source.length(), replace);
- it = inputtext.find(source, it);
- }
- cout << dos("\n\nИзменененый текст:\n") << dos(inputtext.c_str()) << endl;
- ofstream ofs("2.txt");
- ofs << inputtext;
- ofs.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement