Help with CFile

As I am new in C++ I would like to write the folowing code using the CFile class
   do something
Also is there an equivalent to
Who is Participating?
danny_pavConnect With a Mentor Commented:
1.  You can use the member m_hFile which is a file handle and do all the work with that.

-- or --

2.  You can read until end of file
char buf[100];
UINT u_bytes_read = pFile->Read(buf, sizeof(buf));
if (u_bytes_read != sizeof(buf)) {
//end of file encountered

Use GetStatus to check for errors

vardisAuthor Commented:
Edited text of question
vardisAuthor Commented:
thank you for your reply
Can you give me an example of how to use the member m_hFile
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

you use the functions ReadFile and WriteFile on the handle, BUT
you would probably want to use the CFile::ReadFile and CFile::WriteFile which are generally wrappers for these functions but will maintain the state of the object as well.  Using the m_hFile is a way around the class when in fact what you want to do is probably supported already.

also, as far as ferror is concerned, you can use GetLastError(); and the CFile class will throw exceptions, so you can use a try/catch block.
vardisAuthor Commented:
Thank you danny_pav this answers my question.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.