tags:

views:

49

answers:

2

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
i can't, my file is ofstream, any other way?
Roy Gavrielov
@Roy Gavrielov Updated.
phihag
+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
i did what you said and still it prints things to the middle of the file :(
Roy Gavrielov
@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