Re: not writing to file
- From: Adrian <nntp@xxxxxxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 18:05:14 -0700
John Smith wrote:
I try to write some data to a file. After some data had supposedly
been written to the file, I opened the file before the program
closed it and found it empty. What's wrong with my code? Thanks.
From the standard
7.9.3.3 When a stream is unbuffered, characters are intended to appear from the
source or at the destination as soon as possible. Otherwise characters may be
accumulated and transmitted to or from the host environment as a block. When a
stream is fully buffered, characters are intended to be transmitted to or from
the host environment as a block when a buffer is filled. When a stream is line
buffered, characters are intended to be transmitted to or from the host
environment as a block when a new-line character is encountered. Furthermore,
characters are intended to be transmitted as a block to the host environment
when a buffer is filled, when input is requested on an unbuffered stream, or
when input is requested on a line buffered stream that requires the transmission
of characters from the host environment. Support for these characteristics is
implementation-defined, and may be affected via the setbuf and setvbuf functions.
You could try fflush on the stream or closing and opening after each write.
Although the code is incomplete I would guess that there is nothing wrong with
it causing the output not to appear in the file.
It could also be possible that the operating system is also buffering the output
and wont write it until the program has exited.
Adrian
.
- References:
- not writing to file
- From: John Smith
- not writing to file
- Prev by Date: not writing to file
- Next by Date: Re: memory leakage problem
- Previous by thread: not writing to file
- Next by thread: Re: not writing to file
- Index(es):
Relevant Pages
|