So I have been doing well in my C++ class all year, but nearing finals I sort of got behind on this chapter reading and writing files and all that good stuff. Anyhow, I get errors and nothing works and I don't know why. The code needs to access a txt file (which I have) that contains values. It needs to skip the header (which I think it should), and read the values and assign them to the struct. The functions need to access the structs and then the structs updated again, reading from the file again.
This is a SIMPLIFIED version of the code, I removed a bunch of the functions as they aren't really the problem except I am wondering how to get them to access the structs because I haven't gotten it working enough to test that;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <istream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
ifstream inFile;
ofstream outFile;
struct OldNew
{
double Old, New;
};
struct Data
{
OldNew gpsTime, gpsX, gpsY, gpsZ, dist, speed;
};
void SkipHeaderInfo(ifstream &inFile)
{
for(int i = 0; 0 < 14; i++)
inFile.ignore(1024, '\n');
}
void ReadData(ifstream &Data)
{
if(inFile.fail())
cout << "Error occured\n";
else
{
inFile >> Data.gpsTime.New >> Data.gpsX.New >> Data.gpsY.New >> Data.gpsZ.New >> inFile.ignore(1024, '\n');
}
}
void Time(ifstream &Data, double time)
{
time = Data.time.New - Data.time.Old;
}
int main()
{
double time;
inFile.open("VehicleTrajectory.txt");
SkipHeaderInfo();
ReadData();
Time();
inFile.close();
return 0;
}
|
So again, what I need help with;
1) Getting ReadData to read data from the file
- The error I get says something along the line of "has no member named"
and then it says gpsTime, gpsX, gpsY, gpsZ.
2) Making sure the functions will call the structs, no errors so far, but that is because I haven't been able to test it so far.
I guess those are my 2 main problems. Any help appreciated! Thanks!
*I am using Putty and g++ compiler if it makes any difference.