Solved

End of file checking

Posted on 2000-04-16
1
195 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 84
Define unique primary key 9 93
Looking for a specific application/software 2 110
Problem to App 4 83
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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