hi all,
i was trying to write to a pre existent binary file but every time it would change the size of file and remove all of its contents so what i should i do?????
here is an example to what i'am trying to say(it is not exactly the same )
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{char h[10];
char c,d;
for(int i=0; i<10; i++)
h[i]='a';
ofstream out("file2", ios::out |ios::binary);
if(!out){cout<<"cannot open file.\n";}
out.write((char *) &h, sizeof h );
out.close();
out.open("file2", ios::out |ios::binary);
out.seekp(5,ios::beg);
c='z';
out.put(c);
out.close();
ifstream in("file2", ios::in | ios::binary);
if(!in){cout<<"cannot open file "<<endl;}
while(!in.eof()){
in.get(d);
cout<<d<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
and the output is :
z
z
press any key to continue
while waht i was trying to make is to edit the conetent of the file after writing 10 (a)'s to:
a
a
a
a
a
z
a
a
a
a