Currently I need to read data from a file, such like this
Measurements for Lansing, Michigan during April, 2000
63 32 0.00
54 43 0.10
59 39 0.00
46 24 0.00
52 20 0.00
54 30 0.00
The first line is obviously disregarded, since all we want are the numbers.
We are not allowed to use anything from standard template library, vectors to be more precise
I had something like this for now, though I'm not sure if it cuts the first line out or not...I'm also cutting main() off the post, I know it works, its the I/O I don't get.
as for declaring the struct, its
Currently the output yeilds
0 0 (some reference address)
...and thats it
I know i'm somewhere close, but I'm drawing a blank. I set Num = 1 in hopes of skipping the first set in the data, which would be the string of words.
Your Help is Greatly Appreciated.
Measurements for Lansing, Michigan during April, 2000
63 32 0.00
54 43 0.10
59 39 0.00
46 24 0.00
52 20 0.00
54 30 0.00
The first line is obviously disregarded, since all we want are the numbers.
We are not allowed to use anything from standard template library, vectors to be more precise
I had something like this for now, though I'm not sure if it cuts the first line out or not...I'm also cutting main() off the post, I know it works, its the I/O I don't get.
Code:
void read( ifstream& In, ReadData List[], int Size, int& Num )
{
ReadData Temp;
Num = 1;
for (;;)
{
In >> Temp.Min >> Temp.Max >> Temp.Precipt;
if (In.fail() || Num >= Size) break;
List[Num] = Temp;
Num++;
}
}
void process( const ReadData List[], int Num )
{
int I;
//***************************
// Display the column headers
//***************************
cout << "\n";
cout << "Minimum Value Maximum Value Precipitation\n";
cout << "------------- ------------- -------------\n";
for(I=0;I<Num;I++)
{
cout << resetiosflags( ios::right ) << setiosflags( ios::left );
cout << setw(20) << List[I].Min << " "<< List[I].Max << " "<< List[I].Precipt <<endl;
}
}
Code:
struct ReadData
{
int Min,Max;
double Precipt;
};
0 0 (some reference address)
...and thats it
I know i'm somewhere close, but I'm drawing a blank. I set Num = 1 in hopes of skipping the first set in the data, which would be the string of words.
Your Help is Greatly Appreciated.
Comment