Mail Archives: djgpp/1997/02/10/16:14:10
From: | boylesgj AT lion DOT cs DOT latrobe DOT edu DOT au (Gregary J Boyles)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | tellg problem
|
Date: | 10 Feb 1997 13:46:37 GMT
|
Organization: | Comp.Sci & Comp.Eng, La Trobe Uni, Australia
|
Lines: | 95
|
Distribution: | world
|
Message-ID: | <5dn8rt$scs@lion.cs.latrobe.edu.au>
|
NNTP-Posting-Host: | lion.cs.latrobe.edu.au
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
The following two functions are designed to read in data from a file with
the following format :
Number of suburbs (integer)
Suburb 1 (string)
Number of streets (integer)
Street 1 (string)
Street 2 (string)
.
.
.
.
Blank line
Suburb 2 (string)
Number of streets (integer)
Street 1 (string)
Street 2 (string)
.
.
.
.
Blank line
.
.
.
.
The details of each suburb (name and number of streets etc) are stored in a
seperate class SuburbC object.
The variable File is of type fstream and is a data member of class
SuburbListC. It was created via the constructor fstream() i.e. it was an
unattached stream.
The variable FilePosStreetList is of type long and is a data member of
SuburbC.
// Reads in the list of suburbs and streets from the file.
void SuburbListC::Get()
{
static StringC EOL,MainDir=Config->GetMainDir();
int I;
File.open(MainDir+"streets.dat",ios::in);
if (!File)
Error->ErrorMessage(NoFile,MainDir+"streets.dat");
else
{
File>>NumSuburbs>>EOL;
SuburbList=new SuburbC[NumSuburbs];
for (I=0;I<NumSuburbs;I++)
SuburbList[I].Get(File);
}
File.close();
}
A problem occurs in the call to tellg (marked with stars).
The two variables Name and NumStreets are read from the file correctly
however after the call to tellg the file pointer is moved further on in
the file.
It should remain set at the start of the next line from the line
which contains NumStreets.
I.E. The data file.
13 <---
ASHBURTON VIC <--- These values are read from the file correctly.
99 <---
AITCHISON AVENUE <--- The file pointer should remain set at the start
ALAMEIN AVENUE of this line but instead it is moved, by the call
ALBION ROAD to tellg, way beyond this point.
AMBON STREET
AMERY STREET
ANNETTA AVENUE
ANSON COURT
ASHBURN GROVE
BAIRD STREET
BAKER PARADE
void SuburbC::Get(fstream &In)
{
static StringC EOL;
int I;
In>>Name>>NumStreets>>EOL;
*****FilePosStreetList=In.tellg();****
for (I=0;I<NumStreets;I++)
In>>EOL;
In>>EOL;
}
- Raw text -