Solved

Help with CFile

Posted on 1998-08-04
6
233 Views
Last Modified: 2013-11-19
As I am new in C++ I would like to write the folowing code using the CFile class
while(!feof(fp)){
   do something
  }
Also is there an equivalent to
if(ferror(fp))
Thanks
0
Comment
Question by:vardis
  • 3
  • 3
6 Comments
 

Author Comment

by:vardis
ID: 1320196
Edited text of question
0
 
LVL 3

Accepted Solution

by:
danny_pav earned 50 total points
ID: 1320197
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

0
 

Author Comment

by:vardis
ID: 1320198
thank you for your reply
Can you give me an example of how to use the member m_hFile
thanks
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 3

Expert Comment

by:danny_pav
ID: 1320199
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.

0
 
LVL 3

Expert Comment

by:danny_pav
ID: 1320200
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.
0
 

Author Comment

by:vardis
ID: 1320201
Thank you danny_pav this answers my question.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 62
lucky13 challenge 11 145
canBalance challenge 34 85
Trying to run powershell  in a batch file. How do I do this? 8 92
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question