Discussion:
EOF when using CreateFile and unknown sizes of arrays
(too old to reply)
Jack
2009-11-26 06:30:22 UTC
Permalink
Dear gurus,
1) When open a file with CreateFile, how can I tell that
the file has reached the end (EOF)?

2) std::vector<BYTE> vBuffer
vBuffer.resize(???);
or PBYTE vBuffer = new BYTE[???];

When I hava an unpredicted size situation, how
can I let the compiler assist me to handle it automatically?
Thanks
Jacl
Ulrich Eckhardt
2009-11-26 07:43:58 UTC
Permalink
Post by Jack
1) When open a file with CreateFile, how can I tell that
the file has reached the end (EOF)?
If you can't read from it any more. Just check the docs for ReadFile().
Post by Jack
2) std::vector<BYTE> vBuffer
vBuffer.resize(???);
or PBYTE vBuffer = new BYTE[???];
When I hava an unpredicted size situation, how
can I let the compiler assist me to handle it automatically?
You just take the vector, as you showed. Other than that, there is no way to
make the compiler write the code for you. If you don't know the size, there
is no way for the compiler to know it either. However, there is far from
enough context to really give a good advise.

There almost never is a reason to use "new T[]", use std::vector instead.

Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite

Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
Loading...