Hello, i'm writing something to file and it writes it in the middle of the file, is there any function that writes output to the end of the file? thanx in advance. ok this is really wierd i'm running with the visual studio debugger and i see that it writes thing to file like this : A B C D which is good, and than when i'm writing something for example E it writes it here A B E C D this is really wierd, how can i fix it?
+2
A:
With the plain old C functions, open
the file with O_APPEND
or call lseek(fd, 0, SEEK_END)
before writing.
With ofstream
, call file.seekp(0, ios_base::end)
before writing.
phihag
2010-09-12 11:00:09
i can't, my file is ofstream, any other way?
Roy Gavrielov
2010-09-12 11:03:28
@Roy Gavrielov Updated.
phihag
2010-09-12 11:08:38
+3
A:
If you use std::ofstream
and open the file in append mode (using std::ios_base::app
in the mode mask) then all writes will be made at the end of the file.
Charles Bailey
2010-09-12 11:01:52
i did what you said and still it prints things to the middle of the file :(
Roy Gavrielov
2010-09-12 11:07:55
@Roy Gavrielov: Then either you have buggy code or a buggy implementation. Without seeing your code it's impossible to say which is the case.
Charles Bailey
2010-09-12 11:12:04