Solved

End of file checking

Posted on 2000-04-16
1
193 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
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 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

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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