Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <istream>
- #include <fstream>
- #include <string>
- using namespace std;
- void zmienCiag(string nzw, string ciag1, string ciag2)
- {
- int pozycja = 0;
- string tmp = nzw;
- int dlugosc1 = ciag1.length();
- int miejsce = tmp.find(".txt");
- string nowaNazwa = tmp.erase(miejsce,4) +"_nowy.txt";
- ifstream plik(nzw);
- ofstream nowyPlik(nowaNazwa);
- if(plik && nowyPlik)
- {
- string bufor;
- string linia;
- while(!plik.eof())
- {
- getline(plik,linia);
- cout << linia<<endl;
- while(pozycja < linia.length())
- {
- if(+)
- {
- pozycja = linia.find(ciag1);
- linia.replace(pozycja,dlugosc1,ciag2);
- cout << linia<<endl;
- }
- else
- {
- cout << "chuj1";
- }
- }
- pozycja = 0;
- bufor.append(linia);
- }
- nowyPlik << bufor;
- }
- else{
- cout << "chuj2";
- }
- }
- int main()
- {
- string nazwaPliku, c1, c2;
- cout << "Podaj nazwe pliku tekstowego: " << endl;
- cin >> nazwaPliku;
- cout << "Podaj ciag do ktory ma zostac zmieniony : " << endl;
- cin >> c1;
- cout << "Podaj ciag ktory ma zastapic poprzedni: " << endl;
- cin >> c2;
- zmienCiag(nazwaPliku, c1, c2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment