Guest User

Untitled

a guest
Jul 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5.  
  6. using namespace std;
  7. //function: Does the handed over string contain the
  8. //returns -1 if string is not found, else returns int
  9.  
  10.  
  11. int firstTime=0;
  12.  
  13. void write2File(string appendMe)
  14. {    cout<<"writting:"<<appendMe<<endl;
  15.       if (firstTime==0)
  16.         {
  17.             ofstream outfile;
  18.             outfile.open("buibaicity3.txt",ios::binary);
  19.             outfile << appendMe;
  20.             outfile.flush();
  21.             outfile.close();
  22.             firstTime++;
  23.             return;
  24.          }else{
  25.                      ofstream outfile;
  26.                     outfile.open("buibaicity3.txt",ios::binary|ios::app);//|ios::binary
  27.                     outfile << appendMe;
  28.                     outfile.flush();
  29.                     outfile.close();
  30.                     return;
  31.                 }
  32. }
  33.  
  34.  
  35. void readNextLine()
  36. {
  37.  int iterRator=3;
  38.  string endOfSthrings="buibaicity2.dds";
  39.  string stringOfStrings= "flameEmit1";
  40.  string geFillteStrings="flameEmit";
  41. string tempLine;
  42. ifstream myfile("buibaicity2.txt",ios::in|ios::binary);//
  43. int internalIterrator=0;
  44.  
  45.  
  46. if (myfile.is_open())
  47.   {
  48.       while (myfile.is_open()&&(tempLine.find(endOfSthrings)== tempLine.npos))
  49.       {
  50.  
  51.       getline(myfile,tempLine);
  52.       cout << "reading:"<<tempLine<<endl;
  53.       if (tempLine.find(stringOfStrings)== tempLine.npos){
  54.       //if the file doesent contain the searched string append it
  55.       write2File(tempLine);
  56.  
  57.       }
  58.       else{
  59.       string tempCutDownString=tempLine;
  60.               while (tempCutDownString.find(stringOfStrings)!=tempCutDownString.npos)
  61.                     { if (internalIterrator < 4 )
  62.                         {//find Startposition of the searched keyword
  63.                         int startPos=tempLine.find_first_of(stringOfStrings);
  64.                         string frontend,backend;
  65.                         //Cutline into three parts..
  66.                         frontend=tempLine.substr(0,startPos);
  67.                         backend=tempLine.substr((startPos+stringOfStrings.length()),tempLine.length());
  68.                         //generate StringToReplace(iterrator)
  69.                         const char    *charPtr; int x=2;
  70.                         if (x < 10)
  71.                             x=1;
  72.                         char tempChar=(char) iterRator+48;
  73.                         charPtr= &tempChar;
  74.                         string rePlaceMent=geFillteStrings.append( charPtr,x);
  75.                         frontend=frontend.append(rePlaceMent);
  76.                         frontend=frontend.append(backend);
  77.  
  78.                         //insert the generated String into the middleHalf
  79.                        tempCutDownString=frontend;
  80.                         //iterRator++;
  81.                         internalIterrator++;
  82.                         }
  83.                        else
  84.                         {internalIterrator=0; iterRator++;}
  85.                      }
  86.             write2File(tempCutDownString);
  87.  
  88.           }
  89.       }
  90.   }
  91.   else cout << "Error: Specified File or Folder doesent exist."<<endl;
  92.  
  93. myfile.close();
  94. return;
  95. }
  96.  
  97.  
  98. int main()
  99. {   readNextLine();
  100.  
  101.     return 0;
  102. }
Add Comment
Please, Sign In to add comment