Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- //function: Does the handed over string contain the
- //returns -1 if string is not found, else returns int
- int firstTime=0;
- void write2File(string appendMe)
- { cout<<"writting:"<<appendMe<<endl;
- if (firstTime==0)
- {
- ofstream outfile;
- outfile.open("buibaicity3.txt",ios::binary);
- outfile << appendMe;
- outfile.flush();
- outfile.close();
- firstTime++;
- return;
- }else{
- ofstream outfile;
- outfile.open("buibaicity3.txt",ios::binary|ios::app);//|ios::binary
- outfile << appendMe;
- outfile.flush();
- outfile.close();
- return;
- }
- }
- void readNextLine()
- {
- int iterRator=3;
- string endOfSthrings="buibaicity2.dds";
- string stringOfStrings= "flameEmit1";
- string geFillteStrings="flameEmit";
- string tempLine;
- ifstream myfile("buibaicity2.txt",ios::in|ios::binary);//
- int internalIterrator=0;
- if (myfile.is_open())
- {
- while (myfile.is_open()&&(tempLine.find(endOfSthrings)== tempLine.npos))
- {
- getline(myfile,tempLine);
- cout << "reading:"<<tempLine<<endl;
- if (tempLine.find(stringOfStrings)== tempLine.npos){
- //if the file doesent contain the searched string append it
- write2File(tempLine);
- }
- else{
- string tempCutDownString=tempLine;
- while (tempCutDownString.find(stringOfStrings)!=tempCutDownString.npos)
- { if (internalIterrator < 4 )
- {//find Startposition of the searched keyword
- int startPos=tempLine.find_first_of(stringOfStrings);
- string frontend,backend;
- //Cutline into three parts..
- frontend=tempLine.substr(0,startPos);
- backend=tempLine.substr((startPos+stringOfStrings.length()),tempLine.length());
- //generate StringToReplace(iterrator)
- const char *charPtr; int x=2;
- if (x < 10)
- x=1;
- char tempChar=(char) iterRator+48;
- charPtr= &tempChar;
- string rePlaceMent=geFillteStrings.append( charPtr,x);
- frontend=frontend.append(rePlaceMent);
- frontend=frontend.append(backend);
- //insert the generated String into the middleHalf
- tempCutDownString=frontend;
- //iterRator++;
- internalIterrator++;
- }
- else
- {internalIterrator=0; iterRator++;}
- }
- write2File(tempCutDownString);
- }
- }
- }
- else cout << "Error: Specified File or Folder doesent exist."<<endl;
- myfile.close();
- return;
- }
- int main()
- { readNextLine();
- return 0;
- }
Add Comment
Please, Sign In to add comment