Hello, I'm trying to read input from a file to the screen using the fstream library. But what i want to do is to shift the position of EOF to make the input stop at supposedly half the file and not at the end.
Any help is appreciated.
Hello, I'm trying to read input from a file to the screen using the fstream library. But what i want to do is to shift the position of EOF to make the input stop at supposedly half the file and not at the end.
Any help is appreciated.
Last edited by tonit; 01-02-2011 at 01:03 AM.
As you read, check for that value. When you detect it, stop reading.
Right, so your requirements changedOriginally Posted by tonit
Read the entire file and discard the second half, or find out the size of the file and then read just the first half.
Last edited by laserlight; 01-02-2011 at 01:20 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thank you for your quick reply. But i'm curious if i can play around with EOF. So i can make EOF(Supposedly) "End of half-file" instead of "End of File".
Hope i expressed my point clearly here.
No. EOF is just a macro for a negative value used to indicate end of file has been reached.Originally Posted by tonit
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
That is to say, at least on pretty much every system still running, there is no actual "end-of-file" character in a file.
You can't decrease a file's length on some OSes. You can under Windows, but not under Linux afaik. In Linux I'm told that you read in the file and write half of it out again and then delete the original file. So, what OS?
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
hmm... so, are you trying to truncate the file to half its length, or are you trying to only read half of the file?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
SetEndOfFile Function (Windows)
Bookmark the top level if you're into Win32 programming.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.