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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading in binary file 1

Status
Not open for further replies.

yaids

Programmer
Apr 1, 2005
11
AU
Hello,
I want to open a binary file and read in a single octet of data (I assume this to be one-byte?). Is there a C++ function that does this?
 
Yes, of course.
Code:
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("thefile.xxx",ios::binary);
char ch;
if (f.get(ch))
{
   ...
}
Or use old good C library streams from <cstdio>:
Code:
#include <cstdio>
FILE* f;
char  ch;
f = fopen("thefile.xxx","rb);
if (f && (ch=fgetc(f)) != EOF)
{
   ...
}
What's a problem? It's basic C/C++ i/o mechanics...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top