reading data from files...

#include <iostream>
#include <string>
#include <ostream>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cstdio>
#include<fstream>
#include <sstream>
#include <iomanip>
#include <vector>


using namespace std;

int main () {


int lineCount;
string t;

ifstream inputFile("AER13.txt");

if (!inputFile){

cout << "Error opening file !" << endl;
}


else {



cout<<"\nThe position of the get pointer "<<inputFile.tellg();

lineCount=0;

//To count the number of lines that are in the input file, this will be use to be able to determine
// the size of the arrays.

while(getline(inputFile, t, '\n')){

cout<<"\nThe position of the get pointer in while loop"<< inputFile.tellg();

lineCount++;
}

cout<<"\nThe position of the get pointer"<< inputFile.tellg();

cout << "\nThe is " << lineCount <<endl ;



inputFile.seekg (0, ios::beg);

cout<<"\nThe position of the get pointer after calc "<< inputFile.tellg();






double Mean[lineCount];
string time_Stoparray[lineCount], time_Startarray[lineCount];


cout<<"\nThe position of the get pointer "<< inputFile.tellg();



cout<<"\nThe position of the get pointer "<< inputFile.tellg();
// Keep reading while the End Of File character is NOT reached

while(!inputFile.eof()) {

for(int y = 0; y < lineCount; y++){
//Taken input data from Ae, for the start time, stop time, mean, stdev, min and max.

inputFile >> time_Startarray[y] >> time_Stoparray[y] >> Mean[y];

cout <<"\n\nThe value of time start array is " << time_Startarray[y];
}

}

}
return 0;
}


text file would look like this...
00:00 4:00 1.5
4:01 8:00 2.5
8:00 19:00 0.9
19:00 22:30 1.8
22:31 24:00 0.3


please excuses the excess of the library files at the start, this is a scaled down version of the program i'm using, i just didn't bother trying to figure out which libraries aren't need in this..


ideally I want to get this working, to place into a function.

the 1st part while(getline.....) is just been use to find the number of lines in the text file and been used further on to identified the number of calculation necessary (not shown above), this will then be used to set the size of the arrays. then i want to loop through the file again, taking in the values and storing this in the arrays.
this is where i am encountering the problem. i can't seem to set the pointer back to the start of the file. this is where all the inputFile.tellg() are in place for, you should be able to see that after the 1st while loop the value gets set to -1, and can't seem to set this back to 0..

inputFile.seekg (0, ios::beg);

has been identified to reset the pointer, but it doesn't seem to work.

has anyone encounter this previously?? or any suggestions??
any help greatly appreciate.
I guess you need inputFile.clear(); before inputFile.seekg (0, ios::beg); to clear eof error flag
yep.. thats exactly what i need.. thanks for very much...
Topic archived. No new replies allowed.