hi
any one can help me plz ??
my code is about opening file as binary
then get data from file to edit
and rewrite data to file
this is the code:
#include <cstdlib>
#include <iostream>
#include<fstream>
#include<string>
#include<conio.h>
using namespace std;
int main()
{
int i=1,add=0;
string *marry=new string[i];
fstream file;
int spos=0,filepos1=0,change=0;
string mline,newline;
file.open("test.txt",ios:: out|ios::in|ios::binary);
while(!file.eof()){
filepos1=file.tellp();
//get line from file
getline(file,mline);
//copy new line from main line to edit
newline=mline;
//edit the line as string(replace VB with C++)
spos=newline.find("vb");
while(spos!=string::npos){
newline.replace(spos,2,"c++");
spos=newline.find("vb");
}
//Inject Lines to Memory In Dynamic Array
marry[add]=newline;
cout<<marry[add]<<endl;
add++;
i++;
}
file.close();
//Open the file to rewrite data from memory to it
file.open("test.txt",ios:: out|ios::in|ios::binary|ios::trunc);
for(int j=0;j<add;j++){
file<<marry[j]<<endl;
}
file.close();
return 0;
}
Thanks