this is how to create a binary file in c(of course you can use it in c++)
#include <stdio.h>
FILE * filenum; //pointer to file
filenum=fopen("External file name","mode")
mode:r,w or a, read write,or appending
right after r,w or a type 'b' to open the file as binary
for example to create a binary file called my.dat write
FILE * f1;
f1=fopen("my.dat ","wb");
now to read and write to the file,you will use the functions
fread(buffer,siz,num,filenum);
which will read num values(of size siz) from the filenum file and store it
in the proper array named buffer.if a zero value is returned it means that
you have come to the end of the file.
to write you will use
fwrite(buffer,siz,num,filenum);
as above except that if the function returns the number of values written
to the file.
to seek values in the file use the function
fseek(filenum,(long)no_bytes,position);
the internal acces pointer of the file filenum will move no_bytes from
position.
position:0 start of file
1:current position
2:end of file
that's all. hope that helped
_____________________________________________
Free email with personality! Over 200 domains!
http://www.MyOwnEmail.com
|