Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CFile::Open

1 view
Skip to first unread message

Richard Ripps

unread,
Apr 3, 2001, 8:14:37 PM4/3/01
to
i open an existing file with with a filesize of 100 bytes, write some
buffer, and then close the file. i do something like:
.
.
.
myFile.Open("test.txt",CFile::modeWrite | CFile::modetypeText |
CFile::shareExclusive);

myFile.write(buf,50);
myFile.Close();

when i open the file for read, it has my 50 bytes at the beginning of the
file, and the remaining 50 bytes is from the existing file.

why does this happen? why doesn't it write an eof after my 50 bytes and
truncate the file at 50?

any help is appreciated


Sam Hobbs

unread,
Apr 3, 2001, 8:32:41 PM4/3/01
to
CFile::Open has many modes and flags. I would try a couple more to see what
I got.


"Richard Ripps" <r...@nycap.rr.com> wrote in message
news:eOBfhyJvAHA.1456@tkmsftngp02...

Mehdi Mousavi

unread,
Apr 3, 2001, 9:39:55 PM4/3/01
to
There are 2 approaches:

1. Try the CFile::modeCreate flag, that directs it to create a new file. If
the file already exists, it is truncated to 0 length.

2. Try CFile::SetLength(DWORD dwNewLen); in this example,
myFile.SetLength(50);

HTH,
Mehdi
--
Looking for a scandisk-like control (in terms of its UI) to use within your
program? Try mine:
http://www.codeproject.com/useritems/checkerctrl.asp

"Richard Ripps" <r...@nycap.rr.com> wrote in message
news:eOBfhyJvAHA.1456@tkmsftngp02...

0 new messages