for loop not working

example input from file
111 - 111, 111
222 - 222, 222
so on..


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  ifstream file("number.txt");
	string num1[500], num2[500], num3[500], dash;

	if (!file.is_open())
	{
		cout << "File not found." << endl;
		exit(1);
	}

	for (int x = 0; file.good(); x++)
	{
		file >> num1[x];
		file >> dash;
		getline(file, num2[x]), ',';
		getline(file, num3[x]);
		cout << "asdasd";
	}	

	for (int x = 0; file.good(); x++)  //why doesnt this work?
	{
		cout << "hi";           
	}


this function was supposed to see if the user input is in the file. but since it didnt work and i found out it was the 2nd for loop so i tested it by printing out hi. instead all it printed was asdasd.
You wanna do it like this -

1
2
3
4
5
if (playerFile.is_open())
{

}


And all the input/output things goes in there. As long as the file is open do this. thats what the code says.
Topic archived. No new replies allowed.