Click here to Skip to main content
15,887,440 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
SuggestionRe: redirecting output of CMD with administrator privileges Pin
David Crow15-Feb-14 11:10
David Crow15-Feb-14 11:10 
Questionhow to read character by character from text file in c++? Pin
sajedevahedi14-Feb-14 10:32
sajedevahedi14-Feb-14 10:32 
AnswerRe: how to read character by character from text file in c++? Pin
jeron114-Feb-14 10:56
jeron114-Feb-14 10:56 
GeneralRe: how to read character by character from text file in c++? Pin
sajedevahedi14-Feb-14 11:18
sajedevahedi14-Feb-14 11:18 
GeneralRe: how to read character by character from text file in c++? Pin
jeron114-Feb-14 11:30
jeron114-Feb-14 11:30 
AnswerRe: how to read character by character from text file in c++? Pin
Richard MacCutchan14-Feb-14 22:43
mveRichard MacCutchan14-Feb-14 22:43 
AnswerRe: Just put the 'file.get' into a 'while' statement. Pin
Software_Developer15-Feb-14 1:51
Software_Developer15-Feb-14 1:51 
AnswerRe: how to read character by character from text file in c++? Pin
leon de boer4-Mar-14 15:03
leon de boer4-Mar-14 15:03 
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();

QuestionC program help Pin
MalDrHoop14-Feb-14 6:00
MalDrHoop14-Feb-14 6:00 
AnswerRe: C program help Pin
jeron114-Feb-14 6:06
jeron114-Feb-14 6:06 
GeneralRe: C program help Pin
MalDrHoop14-Feb-14 6:11
MalDrHoop14-Feb-14 6:11 
GeneralRe: C program help Pin
jeron114-Feb-14 6:21
jeron114-Feb-14 6:21 
GeneralRe: C program help Pin
MalDrHoop14-Feb-14 6:34
MalDrHoop14-Feb-14 6:34 
GeneralRe: C program help Pin
jeron114-Feb-14 6:38
jeron114-Feb-14 6:38 
GeneralRe: C program help Pin
MalDrHoop14-Feb-14 6:46
MalDrHoop14-Feb-14 6:46 
GeneralRe: C program help Pin
jeron114-Feb-14 6:50
jeron114-Feb-14 6:50 
GeneralRe: C program help Pin
MalDrHoop14-Feb-14 6:53
MalDrHoop14-Feb-14 6:53 
GeneralRe: C program help Pin
MalDrHoop14-Feb-14 6:48
MalDrHoop14-Feb-14 6:48 
GeneralRe: C program help Pin
jeron114-Feb-14 6:55
jeron114-Feb-14 6:55 
GeneralRe: C program help Pin
MalDrHoop14-Feb-14 7:03
MalDrHoop14-Feb-14 7:03 
GeneralRe: C program help Pin
Richard MacCutchan14-Feb-14 7:33
mveRichard MacCutchan14-Feb-14 7:33 
GeneralRe: C program help Pin
MalDrHoop14-Feb-14 7:44
MalDrHoop14-Feb-14 7:44 
GeneralRe: C program help Pin
Richard MacCutchan14-Feb-14 22:33
mveRichard MacCutchan14-Feb-14 22:33 
GeneralRe: C program help Pin
MalDrHoop15-Feb-14 1:44
MalDrHoop15-Feb-14 1:44 
GeneralRe: C program help Pin
Richard MacCutchan15-Feb-14 2:08
mveRichard MacCutchan15-Feb-14 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.