?
Solved

Help with CFile

Posted on 1998-08-04
6
Medium Priority
?
238 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

770 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