[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help with CFile

Posted on 1998-08-04
6
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

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

Accepted Solution

by:
danny_pav earned 200 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 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