I came across the strange behavior of thestream, โleast strange to me. Here is my program, I am using Visual Studio 2010 Express Edition.
int main () { std::ofstream file("file.txt"); file << "something1"; file.close(); file.open("file.txt", std::ios::ate | std::ios::in ); file << "something2"; file.close(); return 0; }
This gives the correct result.
something1something2
Now, if I replaced the 9th line with the following code,
file.open("file.txt", std::ios::ate);
I get this conclusion.
something2
But if I replace the 9th line again, this time with this code
file.open("file.txt", std::ios::ate | std::ios::in );
I get this conclusion.
something1something2
Now, probably, the question is, can someone help me figure this out? Why the latter solution works, but the average does not.
EDIT: Fixed main function. You will learn something every day.
source share