how to read character by character from text file in c++?
-
hi there I would appreciate if someone could tell me how can I read character by character from a file? I did some research about it but there weren't work in mine for example: it couldn't verified infile although i use fstream library or is.get none of them working
char singlecharacter;
int singleCharacter ;
ifstream file ("vurudi");
file.is_open() ;
infile.get(singlecharacter); -
hi there I would appreciate if someone could tell me how can I read character by character from a file? I did some research about it but there weren't work in mine for example: it couldn't verified infile although i use fstream library or is.get none of them working
char singlecharacter;
int singleCharacter ;
ifstream file ("vurudi");
file.is_open() ;
infile.get(singlecharacter); -
tnx for your replay. as I said I used the code which I mention before from this link but it didnt work
-
tnx for your replay. as I said I used the code which I mention before from this link but it didnt work
-
hi there I would appreciate if someone could tell me how can I read character by character from a file? I did some research about it but there weren't work in mine for example: it couldn't verified infile although i use fstream library or is.get none of them working
char singlecharacter;
int singleCharacter ;
ifstream file ("vurudi");
file.is_open() ;
infile.get(singlecharacter);sajedevahedi wrote:
none of them working
Unfortunately that does not help us to help you. Please be specific about the results you expect versus the results, or errors, you receive. In the meantime you may find http://msdn.microsoft.com/en-us/library/f5tsy854.aspx#vclrfthegetfunctionanchor12[^] useful.
Veni, vidi, abiit domum
-
hi there I would appreciate if someone could tell me how can I read character by character from a file? I did some research about it but there weren't work in mine for example: it couldn't verified infile although i use fstream library or is.get none of them working
char singlecharacter;
int singleCharacter ;
ifstream file ("vurudi");
file.is_open() ;
infile.get(singlecharacter);Just put the file.get into a while statement.
#include
#include
#includeusing namespace std;
int main()
{char singlecharacter ; ifstream file ("vurudi.txt"); file.is\_open() ; while(file.get(singlecharacter)) { cout<
-
hi there I would appreciate if someone could tell me how can I read character by character from a file? I did some research about it but there weren't work in mine for example: it couldn't verified infile although i use fstream library or is.get none of them working
char singlecharacter;
int singleCharacter ;
ifstream file ("vurudi");
file.is_open() ;
infile.get(singlecharacter);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 fileUsing 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 fileUsing 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();