Binary Files In Vc++

how can i
1)create
2)open
3)write into
4)read data from
a binary file(both read and write mode) in VC++ using MFC
[148 byte] By [punitpandia] at [2007-11-19 19:43:03]
# 1 Re: Binary Files In Vc++
Here ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cfile_class_members.asp)
DragForce at 2007-11-10 23:43:00 >
# 2 Re: Binary Files In Vc++
how can i
1)create
2)open
3)write into
4)read data from
a binary file(both read and write mode) in VC++ using MFC
Well check this: File Handling with C++ (http://msdn2.microsoft.com/en-us/library/ms235422.aspx) and File Handling and I/O in C++ (http://msdn2.microsoft.com/en-us/library/d3ccyysc(VS.80).aspx)
jayender.vs at 2007-11-10 23:44:05 >
# 3 Re: Binary Files In Vc++
why would you want to do it using MFC? The way to do it in C++ is with streams but even streams are a compromise. If performance or higher control of your data's format are importan use fopen() and fprintf(). You loose safe type checking, but in exchange for greater data formate control and performance it's a no brainer.
JMS at 2007-11-10 23:45:04 >
# 4 Re: Binary Files In Vc++
You can use low level c style commands and wrap them in your own class.

These are some of the commands:

int iFd;
char szFile[256];

// Open as read only and access the file randomly with "fseek"
iFd = open (szFile, O_RDONLY|O_BINARY|O_RANDOM, 0);

// Open as read/write and access the file randomly
iFd = open (szFile, O_RDWR|O_BINARY|O_RANDOM, 0);

O_RDWR|O_BINARY|O_RANDOM|O_CREAT|O_TRUNC

// Create new file and if file exist truncate it
iFd = open (szFile, O_RDWR|O_BINARY|O_RANDOM|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE);

// To read the file
iReadCount = read (iFd, pBuf, iCount);

// To write to the file
iWriteCount = write (iFd, pBuf, iCount);

// Close file
close (iFd)

Hopes this helps,

Standby1
standby1 at 2007-11-10 23:46:06 >