Skip to main content
gamedev.net
🔒 Locked

Simple Simple ifstream question

Started by Ademan555 14 replies 350+ views
Original Post
Ademan555
Ademan555
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
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
SiCrane
SiCrane
eof is not a recognized character value in C or C++. It has no ASCII value either. If you want to append to a file then use the ios_base::app flag when opening the stream.
Ademan555
Ademan555
Ah... ok, and then i hafta ask, that will open as if its binary if its the first time the file is used right?

if that came out wrong, i mean, will it behave as ios::binary the first time the file is used?
thanx
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
SiCrane
SiCrane
I don''t understand your question. If you want it to be opened as a binary file then use the binary flag.
Fruny
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.


“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
Ademan555
Ademan555
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...
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
SiCrane
SiCrane
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?
Ademan555
Ademan555
Because thats too good of an idea, lol, will do
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
Fruny
Fruny
quote:
Original post by SiCrane
Didn''t you notice I said character value? An int_type is not a character value.


Curse you, foiled again.
"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
SiCrane
SiCrane
quote:
Original post by Fruny
Curse you, foiled again.


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.
Fruny
Fruny
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 ).
"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
Shannon Barber
Shannon Barber
I thought it had a value of 26.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
SiCrane
SiCrane
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.
Ademan555
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
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
SiCrane
SiCrane
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.
Fruny
Fruny
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)
"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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.