Code:
while(infile >> data)
{
cout << data;
}
it wasn't the writing loop that was causing problems -
I don't remember exactly why it does this but it's something to do with how infile.fail() will not return true untill *after* EOF is reached - meaning after you do that last infile >> data;
which means you could also write
Code:
while(!infile.fail())
{
if(infile >> data) cout << data;
}
since when(actually the next operation *after*) infile reaches eof, either a >> operation or the infile itself will evaluate to false(>> returns a reference to the ifstream object if i remember correctly);
also it's actually quite silly to write
Code:
.open("c:\myfile");
instead of
.open("myfile");
because not only does this limit the simple program to DOS/Windows (which it doesn't need to be limited to, for such a simple program,) but also it means if you don't have a C: drive (rare but yes I have done that - windows sometimes acts real weird without a C: drive ) it won't work.
Anyway to sum up, the problem was not the write operation but the read operation.