🔒 Locked
Simple Simple ifstream question
Advertisement
Original Post
How do you find the end of the file? because once you hit the eof character, your ifstream object invalidates itself doesnt it? or... can i just search for it, and then write from there? (i guess fstream woulda been more appropriate as i plan to write to the file as well ) ... also, whats the ascii number for the eof character?
thanx
-Dan
Sicrane - EOF has a value of traits_type::eof() (i.e. -1). You can get it as the return value from single character operations like istream::get(). That''s why they return int_type and not char_type.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
Well, if i was to use that flag (oh i guess i could use the bitwise or couldnt i?) but anyways, the first time you open a file (ifstreams automatically create files at the specified paths if they dont already exist... or if nothing else, used to) and, im wondering if it would be safe to ALWAYS use the app flag, and that it would still create the file...
quote:
Original post by Fruny
Sicrane - EOF has a value of traits_type::eof() (i.e. -1). You can get it as the return value from single character operations like istream::get(). That''s why they return int_type and not char_type.
Didn''t you notice I said character value? An int_type is not a character value.
Ademan555: why don''t you just try it and see what happens?
quote:
Original post by SiCrane
One of these days we should start keeping score. You''d also get points for editting one your posts while I''m in the middle of writing a post that quotes it.![]()
Well, thanks for giving me a way to score a few points.
I blame the absence of a preview button, but also the fact that letting incorrect information stand - even if corrected in a later post - can mislead whomever is reading it (as well as irreparably damage my mystique
I thought it had a value of 26.
The ASCII encoding for the value of 26 is SUB, which means is a control character used to substitute for a character that has been found to be invalid or in error. I haven''t seen it used except as a result in serial line communications where disruption on individual characters can be detected.
The operating system keeps track of the size of the file. If there was an actual EOF byte then there would be binary files you couldn''t write to disk.
ASCII was written as a transmission format so there is a end of trnasmission control code and several seperator control codes, but those are application defined codes for deliminating transmissions into logical segments.
ASCII was written as a transmission format so there is a end of trnasmission control code and several seperator control codes, but those are application defined codes for deliminating transmissions into logical segments.
quote:
Original post by Ademan555
I DID think there was an eof character though also... how else would it be known? since theres no size marking at the beggining of the file...
-Dan
Not as part of the data IN the file, but as part of the filesystem entry for that file. After all, the file name, timestamps, ownership, permissions, location on disk ... are not in the file either, and yet, the OS is keeping track of all that somehow.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement