I'm not quite sure what you're trying to accomplish with the first way of reading the data. You're limiting yourself to 100 characters per line, so assuming you want to append the \n character is not a good method. But anyway, that's not your question. "Doesn't read to the end" isn't quite helpful enough to get an answer. Does it read the whole file minus the last buffer (i.e. less the last line) or something along those lines? Stick to std::getline, you'll be happier.
The reason you need in.clear() is because it clears all set bit flags that contain state which are still set from the previous file. It's annoying, I know, but if you're re-using your variable to open a new file then just get used to having to clear your flags
-eli
=--=--=--=--=--=--=--=--=--=--=--=--=--=
Please rate this post to show your appreciation for those that helped you.
Thanks Eli, I was assuming that all states get cleared when I closed the stream.
About my first question, what I was trying to accomplish is to use in.getline() to read the source code and cout them. I forgot to mention that Strfile.cpp was the file that contained the attached source code.
This is the output from running the program, as you can see the getline() did not read through the end of the source file.
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
You read a blank line... that blank line fills zero characters of the buffer. The get function returns 0 as the # of characters read into the sz buffer. The while loop ends because it thinks it reached EOF.
=--=--=--=--=--=--=--=--=--=--=--=--=--=
Please rate this post to show your appreciation for those that helped you.
Bookmarks