?
Solved

End of file checking

Posted on 2000-04-16
1
Medium Priority
?
202 Views
Last Modified: 2013-11-20
HI,
 How to check the end of a file condition? I have

void CProj1Doc::Serialize(CArchive& ar)
{
      char str[100];
      if (ar.IsStoring())
      {      
      const CFile* fp = ar.GetFile();
      ar.ReadString(string);
      while (NOT_ENDOF_FILE)
      ar.Read(str,10);
                        
      }
}

Also let me know usage of ReadString instead of Read function.
0
Comment
Question by:mkjoshi
[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
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 150 total points
ID: 2720792

I don't understand your code; if you're storing, why are you reading from the archive? That'll just get you a bunch of assertions.

Here's code that works:


void CProj1Doc::Serialize(CArchive& ar)
{
   CString str;
   if (!ar.IsStoring())
   {
      const CFile* fp = ar.GetFile();
      while (ar.ReadString(str))
      {
         // str is a string--you can do something with it
      }
   }
}

and that's that. That code will read the file line-by-line. The loop is controlled by ReadString()--that function itself will return NULL when the file ends, and that will stop your loop.

..B ekiM
0

Featured Post

Industry Leaders: 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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…

719 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