Well, how about this.
After playing some more I finally figured it out. The file stream was going into failstate, so just closing and reopening a file isnt going to work in this instance. So, I used the magical:
And now...it works like a charm. Amazing, the simplest things can be the hardest to figure out.
Thanks for all your help everyone!
Here is the code for example:
using namespace std;
// lets get them all on one line
while(inData >> num)
outData << num << " ";
outData << endl;
count = 0;
avg = 0;
total = 0;
outData << fixed << showpoint
while(inData >> num)
total += num;
avg = total / count;
outData << avg << endl;
I'm glad you got it to work.
Here's a post-mortem evaluation. How much truth there is in it is debateable, but in an effort to understand what is happening, it's worth the effort, at least to me.
If close() truly isn't a member function ifstreams then calling close() could cause the stream to fail and remain unavailable until the the stream is "cleared" with clear(). Finding EOF may also send flip the fail bit, necessitating the call to clear() when end of file has been reached and before resetting the file pointer, but who knows.
My compiler, may not be as persnickity as others and allows the call to close() without putting up a stink allowing the code to run as initially posted, whereas mol's may not let that happen.
>>>If close() truly isn't a member function ifstreams then calling close() could cause the stream to fail and remain unavailable until the the stream is "cleared" with clear().
First, close() is a member of ifstream and ofstream. fstream is derived from both ifstream and ofstream, therefore it also has the close method. If it's not in your docs, its an oversite (if you're using the MSVC docs, they don't list many of the fstream members if they've been defined in one of the base classes, which in the case of fstream, is just about all of its functions).
Second, if you try to call a function of a class that is not really a member function of the class, your compiler should choke on it. The exception would be when you're calling a function that's implemented in a seperate .dll. There are some cases there where you could actually call a function that didn't exist.