Inputting data from text

Hi there, I'm trying out something new too me (reading data from a text file) and are having a few problems. The text file is like this:

1
2
3
4
5
6
7
8
9
10
2.0
16.04
147.9
3.73
5
1	0.000000        0.000000        0.000000
1	0.000000        0.000000        1.089000
2	1.026719        0.000000       -0.363000
2	-0.513360       -0.889165       -0.363000
2	-0.513360        0.889165       -0.363000


And my program is like this:

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
void methane_coords(int atom_types, double sigma, double epsilon, double mass)
{
	double Methane;
	double atom_number;
	int type[5];
	double x[5];
	double y[5];	
	double z[5];
		
            string dummystring;
            string s;

            ifstream Dfile;
            std::stringstream out;

			out << Methane;
            s = out.str() + ".TXT";
            Dfile.open (s.c_str());
			
			if (Dfile.fail())
            {
                return;
            }
			
			Dfile >> atom_types;
			Dfile >> mass;
			Dfile >> epsilon;
			Dfile >> sigma;
			Dfile >> atom_number;

			for (int i=0; i<atom_number; i++)
			{
                        Dfile >> type[i];
                        Dfile >> x[i];
			Dfile >> y[i];
			Dfile >> z[i];
			}

			Dfile.close();

}

int main()
{
	methane_coords(atom_types, sigma, epsilon, mass);
	cin.ignore();
}


Now, I am wanting to check if it is being read correctly, but I am getting errors in my program. Mostly that atom_types, sigma, epsilon and mass are undeclared identifier. I'm going to have several of these coordinate functions eventually so these variables will be redefined depending on which function is being run. Any help with this is appreciated.

Cheers
What the error message said. Where are the variables you use on line 45 declared? the compiler has no idea what they are.

Another issue is that the changes you do to them in methane_coords() will have no effect on their values in main(). To fix this, change the parameter types to int& (and double&).
Thanks very much, I sorted it!
Topic archived. No new replies allowed.