I have the following code snippet :
ofile.open("New1.dat",ios::app|ios::binary|ios::ate);
long bytes = ofile.tellp()/sizeof(t);
cout<<ofile.tellp()<<endl; //line 1
t.input(bytes);
ofile.write((char *)&t,sizeof(t));
ofile.close();
When I remove ios::app
or ios::ate
, the output of line 1
is 0, howeever only when both of them are together, they give the correct file location. Why does this happen?
P.S. I know the difference between ios::app and ios::ate.
Thanks in advance!