cannot find data in the file

is anything wrong with my code

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
  void display()
{
	bool check = true;
	ifstream file;
	file.open("file.txt", ios::in);

	string name, semester, id, findid, gpa;

	if (file.fail())
	{
		cerr << "File Not Created or File Name is Not Valid";
	}
	else
	{
		cout << "\nEnter The Id : ";
		cin >> findid;
		while (file >> id && cin.ignore(40, '\n'), getline(file, name) && file >> semester >> gpa)
		{
			if (id == findid)
			{
				cout << name << endl;
				cout << id;
				cout << semester << endl;
				cout << gpa << endl;
				check = false;
			}
		}
		file.clear();
		file.seekg(0, ios::beg);
	}

	if (check == true)
		cout << "\nStudent Not Found";
}





data in file
12345
Muhammad Salman Zafar
4th
3.00
12346
Muhammad Salman Zafar
4th
3.00
12347
Muhammad Salman Zafar
4th
3.00

if i enter 12345

i get this output
12345
space
Muhammad
Salman 
and cmd is stop not moving

ouh i fix it i don't need to use cin.ignore() , file.ignore();
Topic archived. No new replies allowed.