When using a file stream I test for .eof(); is the eof() bit data within the file or a bit that fstream adds to the stream to indicate the end? Basically besides wanting to know what eof() is I want to know if eof() is a character like '\n' or not.
is the eof() bit data within the file or a bit that fstream adds to the stream to indicate the end?
Both, although it depends on how the file was opened. A file opened as text can be ended before the file physically ends using the EOF character, whose value escapes me at the moment. If this character is found, no more data will be read past that, and attempting to read without resetting the stream will return -1.
Binary files will continue reading until the end no matter what the contents of the file are.
How could I test to see if I have an "eof" bit in my text file? Right now I have a text file which I believe I may have inadvertently included a "eof" bit using getline.
Is it possible that I could have copied a eof bit into a text file using getline?
EOF is not a bit. It's an entire character. I believe it's the ASCII control character 3 or perhaps 4. It's very hard if not impossible to accidentally write it.
and it is telling me that it is character 17; but it doesn't look like it is my problem,because after I clear it, it then throws a fail() bit. I guess I did something else stupid. thanks for the help.
A holdover from CP/M is to mark the end of a text file with ^Z. DOS systems, and some others, still respect it, but it is really useless fluff... as the filesystem keeps track of exactly how many bytes are in your files for you. I don't know whether or not the STL streams pay it any attention. (I don't think they do.)
The STL streams keep track of whether or not you have tried to read past the end of the file, at which point they toggle their "eof bit". You can ask whether the internal eofbit is set using the stream::eof() function.
If you have strange characters appearing in your file, it is because you are putting them there.
In the case of the above code, clear()ing the stream doesn't change the fact that you cannot read any more characters from it. So attempting to get() another character will still fail -- and xx will have whatever random value it had before the call to get().