There are a number of ways to do this depending on your preference and setup of C++ program Using standard windows API:
HANDLE Handle;
char Ch;
unsigned long Li;
Handle = CreateFile("c:\\yourfile.txt",
GENERIC_READ, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0); // Try to open file
if (Handle != INVALID_HANDLE_VALUE){ // Check file opened
ReadFile(Handle, &Ch, 1, &Li, 0); // Read a character
}
CloseHandle(Handle); // Close the file
Using the standard ifstream unit:
#include <fstream>
char Ch;
ifstream myFile;
myFile.open("c:\\yourfile.txt"); // Try to open file
if (myFile.is_open()) { // Check file opened
myFile.read(Ch, sizeof(Ch)); // Read a character
}
myFile.Close(); // Close the file
Using the standard MFC CFile assuming you are using MFC:
UINT nActual = 0;
char Ch;
CFile myFile;
if ( myFile.Open( _T("c:\\yourfile.txt"), CFile::modeRead | CFile::shareDenyWrite ) )
{
nActual = myFile.Read( Ch, sizeof(Ch) );
}
myFile.Close();