|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Reading a single character from a file (C++)
so if I have a file:
ifstream fin; fin.open("C:\file.txt"); and I want to read in the contents of the file a single character at a time... while (!fin.eof()) { someint = fin.get_single_number(); } Im pretty sure there is some member of the fstream class that does this...but to be honest, I cant remember it at all...any help would be greatly appreciated... |
|
#2
|
||||
|
||||
|
Code:
int c = input.get(); // get character
while (!input.eof()) {
output.put(c); // put character
c = input.get(); // get character
The get() function takes a single character from the input stream.
__________________
--Dave-- U2kgSG9jIExlZ2VyZSBTY2lzLCBOaW1pdW0gRXJ1ZGl0aW9uaXMgSGFiZXM= |
|
#3
|
||||
|
||||
|
Well I don't know if that worked for you, but the way I learnt is like this:
ifstream fin; fin.open("C:\file.txt", ios::in) unsigned char ch; For the second part Either this: while(!fin.eof()) { fin.get(ch); //Do whatever } Or this: fin >> ch; |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Reading a single character from a file (C++) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|