kaburen

cpplab

Nov 21st, 2019 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <istream>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. void zmienCiag(string nzw, string ciag1, string ciag2)
  9. {
  10.     int pozycja = 0;
  11.     string tmp = nzw;
  12.     int dlugosc1 = ciag1.length();
  13.     int miejsce = tmp.find(".txt");
  14.     string nowaNazwa = tmp.erase(miejsce,4) +"_nowy.txt";
  15.     ifstream plik(nzw);
  16.     ofstream nowyPlik(nowaNazwa);
  17.  
  18.     if(plik && nowyPlik)
  19.     {
  20.        
  21.         string bufor;
  22.         string linia;
  23.  
  24.  
  25.         while(!plik.eof())
  26.         {
  27.            
  28.             getline(plik,linia);
  29.             cout << linia<<endl;
  30.             while(pozycja < linia.length())
  31.             {
  32.                 if(+)
  33.                 {
  34.                 pozycja = linia.find(ciag1);
  35.                 linia.replace(pozycja,dlugosc1,ciag2);
  36.                 cout << linia<<endl;
  37.                
  38.                 }
  39.                 else
  40.                 {
  41.                     cout << "chuj1";
  42.                 }
  43.             }
  44.             pozycja = 0;
  45.             bufor.append(linia);
  46.         }
  47.  
  48.         nowyPlik << bufor;
  49.     }
  50.     else{
  51.         cout << "chuj2";
  52.     }
  53.  
  54. }
  55.  
  56. int main()
  57. {
  58.     string nazwaPliku, c1, c2;
  59.     cout << "Podaj nazwe pliku tekstowego: " << endl;
  60.     cin >> nazwaPliku;
  61.     cout << "Podaj ciag do ktory ma zostac zmieniony : " << endl;
  62.     cin >> c1;
  63.     cout << "Podaj ciag ktory ma zastapic poprzedni: " << endl;
  64.     cin >> c2;
  65.     zmienCiag(nazwaPliku, c1, c2);
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment