www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/20/19:28:43

From: stupy AT thecds DOT com (Steve Tupy)
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp
Subject: Re: Can not reset an open ifstream file.
Date: Fri, 20 Sep 1996 13:16:33 GMT
Organization: CompuData Systems
Lines: 67
Message-ID: <51u5nl$ofd@nntp.igs.net>
References: <51qo44$e2 AT lion DOT cs DOT latrobe DOT edu DOT au>
NNTP-Posting-Host: igloo.thecds.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

So like, cs3prj04 AT lion DOT cs DOT latrobe DOT edu DOT au (Cs3prj Group 04) was
'splainin'  :

>After running the below program I would be perfectly justified in saying
>that the fools who designed the iostream/fstream classes have provided no
>means of reseting an open file so that it can be read again.

	Like the fool who wrote this who refuses to read up on things? Hey, I
had to say it as you are very quick to assault the masses. 

>With the do while loop commented out  seekg works as you would expect it to
>and you see, on the screen, the first line of the file printed out twice.

Of course, you read a line and THEN check for the eof marker.
Criticize only what you know. The second string is the first string
after a failed attempt at the read, that is all... your mistake to
print it out twice..

>Can any body show me that I am wrong.

	VERY easily!

>#include <fstream.h>
>#include <iostream.h>
>#include "string.hpp"

>void main()
>{
>  //fstream In("main.cpp",ios::in|ios::out);
>  ifstream In("main.cpp");
>  StringC Line;
>  In>>Line;
>  cout<<Line<<endl;
>  do
>  {
>    In>>Line;
>  }
>  while (!In.eof());

	Try...

	while(In) {
		In  >> Line;
		if(!In) break;
		cout << Line << endl;
	}
	In.clear();   // eof constitutes an invalid file pointer
	In.seekg(0);
	// NOW YOU CAN CONTINUE!!!

Really, in closing, it is understandable that you are frustrated, but
approach to problem solving is everthing, you really need not castrate
the language in spite of yourself. Now go and read a few books,
please!

BTW, this does NOT belong in comp.lang.c... wrong area altogether!

Take care!


Steve Tupy
CompuData Systems
Oshawa, Canada.
stupy AT thecds DOT com
Web - www.thecds.com
Home of Base Runner, Userstat, The Enforcer, SpotChek etc...

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019