Facebook
From Dungx, 2 Months ago, written in C++.
Embed
Download Paste or View Raw
Hits: 263
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     fstream fi("donmau.txt");
  8.     fstream fo("out.txt");
  9.     while (!fi.eof())
  10.     {
  11.         string line;
  12.         getline(fi, line);
  13.        
  14.         string what, with;
  15.         int i = 0, count = 0;
  16.         int index_start = 0;
  17.         while (i < line.size())
  18.         {
  19.             if (count == 0 && line[i] == '#')
  20.             {
  21.                 what += line[i];
  22.                 count = 1;
  23.                 index_start = i;
  24.             } else if (count == 1 && line[i] != '#')
  25.             {
  26.                 what += line[i];
  27.             } else if (count == 1 && line[i] == '#')
  28.             {
  29.                 what += line[i];
  30.                 count = 0;
  31.                 cout << "Replace " << what << " with: "; getline(cin, with);
  32.                 line.replace(index_start, what.size(), with);
  33.                 what = "";
  34.                 i = line.find('#')-1;
  35.             }
  36.             i++;
  37.         }
  38.         fo << line << endl;
  39.     }
  40.     fi.close();
  41.     fo.close();
  42. }
  43.