May 13, 2005 #1 yaids Programmer Joined Apr 1, 2005 Messages 11 Location 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?
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?
May 13, 2005 1 #2 ArkM IS-IT--Management Joined Oct 21, 2002 Messages 1,819 Location RU 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... Upvote 0 Downvote
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...