Need help with Structs and Functions!

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.
I cant see you passing any parameter to ReadData, SkipHeaderInfo and Time from main function.
Yes, I know, I was hoping someone could clarify that along with the functions.

Would I just add (ifstream &inFile) for SkipHeaderInfo, (ifstream &Data) for ReadData, and (ifstream &Data, double time) for Time?
for SkipHeaderInfo, yes. In ReadData, Data is a structure, therefore you cant pass Data as an ifstream. Pass inFile as ifstream and another variable as Data data-type. i.e.
void ReadData(ifstream &inFile, Data yourvariable)
You automatically gives yourvariable the members of both OldNew and Data.
I hope this helps a bit, I'm a beginner as well.
Thanks for the help, I had some help from someone else on another site. I think I will just try and get a hold of my teacher, I now have 8 times as many errors as when I started (mostly because of help from the other site I think).
Topic archived. No new replies allowed.