Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read a binary file

Status
Not open for further replies.

balajee

Programmer
Joined
Jun 29, 2000
Messages
134
Location
NZ
Hi

How do we read a binary file in Visual C++?

Thanks
 
Hi,
you can use CStdioFile class for that. like the following:

Code:
CString strPath = "C:\\myfile.bin";
CStdioFile myFile;
TCHAR strBuf[16]; //or CString

BOOL bResult = myFile.Open(strPath,CFile::modeRead
                          | CFile::typeBinary);
if(!bResult)
{
  AfxMessage(strPath + " Could not be oppend");
}
else
{
  while(myFile.ReadString(strBuf))
  {
    _tcscat(strBuf,_T("\n"));
    // write to another file 
  }
}

i hope it can help you.
brgd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top