How do i read from a text file?
How do i read from a text file?
Code:char Buffer[256]; ifstream File; File.open("MyFile.txt", ios::in); if(!File.fail()) { while(!File.eof()) { File >> Buffer; cout << Buffer << " "; } File.close(); }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
the ios::in was the bit i was after thanks
A buffer overflow instatnly crashes it, any way around it?
Replace File >> Buffer; with
File.getline(Buffer, 255, EOF);
can u xplain what that does plz it seems rather weird
Whatch out when using Microsoft VC++ 6.0
getline() reads a line from the file (with a max of 255 chars) of course .Originally posted by krappykoder
can u xplain what that does plz it seems rather weird
can i read from a non-static line in a file so it searchs for
password=
or whatever?
What you have to be careful about is actually using >> to read/inpout since it reads only to the character return not skipping it while getline() reads the entire line and skips past the character return.Whatch out when using Microsoft VC++ 6.0
But that's what it's suppose to do (read the manual pages). I'm just saying the geline function in VC++ 6.0 is not working like descibed in the manual pages because it has a bug!Originally posted by correlcj
What you have to be careful about is actually using >> to read/inpout since it reads only to the character return not skipping it while getline() reads the entire line and skips past the character return.
And I am agreeing with you, mi amigo! No disputes here!But that's what it's suppose to do (read the manual pages). I'm just saying the getline function in VC++ 6.0 is not working like descibed in the manual pages because it has a bug!
my question any1?