Solved

Help with CFile

Posted on 1998-08-04
6
231 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
java ^ examples 8 57
Execute multiple curl cmds with sleep and send output to file 10 80
wordmultiple challenge 12 90
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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now