getline error: function not found

I'm trying to get this data from a text file and it's giving me a weird errer where it's telling me it can't find a function called gerline. I don't know what's causing this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int getQuant (int I)
{
	int Z=I+1;
	int stuff=6;
	snacks thing[6];
	fstream doneDone("DrinkMachine.txt");
	while (stuff!=0)
	{
		getline (doneDone, thing[1]);
		getline (doneDone, thing[2]);
		getline (doneDone, thing[3]);
		getline (doneDone, thing[4]);
		getline (doneDone, thing[5]);
		getline (doneDone, thing[6]);
		stuff = stuff-1;
	}
	thing.quant[Z] = thing.quant[Z]-1;
	return I;
}
Two problems with your code:

1) With this form of getline, getline expects the second argument to be a string. It's not. The type of your second argument is snacks. Presumably, you have not provided an overload of getline the takes an istream and a snacks object.

2) Line 14: You're making an out of bounds reference. thing is declared with a dimension of 6. That means the elements of thing are [0] to [5]. thing[6] does not exist. In C++ elements of an array are 0 based, not 1 based.



Topic archived. No new replies allowed.