Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main() {
- string nazwaPliku, nowyPlik, c1, c2;
- cout << "Podaj nazwe pliku tekstowego (bez roszerzenia): ";
- cin >> nazwaPliku; nowyPlik = nazwaPliku + "_nowy.txt"; nazwaPliku += ".txt";
- cout << "Podaj ciag znakow ktory ma zostac zastapiony: ";
- cin >> c1;
- cout << "Podaj ciag znakow, ktorym chcesz go zastapic: ";
- cin >> c2;
- fstream plik;
- fstream plik2;
- plik.open(nazwaPliku.c_str() , ios::in);
- plik2.open(nowyPlik.c_str() , ios::out | ios::trunc);
- if(plik.good() && plik2.good())
- {
- string linia;
- while(!plik.eof())
- {
- getline(plik, linia);
- int n = linia.find(c1, 0);
- if(n != -1)
- {
- linia.replace(n, c1.size(), c2);
- }
- plik2 << linia << endl;
- cout << linia << endl;
- }
- }
- plik.close();
- plik2.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement