student line up using c++ strings

Hi, i am having a small problem with my code. Everything seems to be working but one part

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
string filename;
	string first;
	string last;
	string rand;
	ifstream infile;
	string word;
	int count = 0;


	cout << "Enter the name of the file with your students names.\n";
	cin >> filename;
	cout << endl << endl;
	infile.open(filename.c_str());

	if (infile.fail())
	{
		cout << "Sorry, file " << filename << " was not found.\n";
		cout << "\nEnding program ...\n\n";
		return 1;
	}

	
		cout << "Reading file " << filename << endl << endl;

		if (infile)
		{
			infile >> first;

			while (infile >> rand)
			{
				
				if (rand <= first)
				{
					first = rand;
				}
				else if (rand >= last)
				{
					last = rand;
				}
				count++;
			}
			count++;
		}
		infile.close();
		if (count == 0)
		{
			cout << "There is no one in line" << endl;
			cout << first << last << endl;
		}
		else if (count == 1)
		{
			cout << "There is only one person in line" << endl;
			cout << "The first person in line is: " << first << endl;
		}
		else
		{
			cout << "The Number of people in the class is: " << count << endl;
			cout << "The first person in line is: " << first << endl;
			cout << "The last person in line is: " << last << endl;
		}
		
	
	
	return 0;
}



Enter the name of the file with your students names.
lineup1.txt


Reading file lineup1.txt

The Number of people in the class is: 9
The first person in line is: Barb
The last person in line is: Zev
Press any key to continue . . .



Enter the name of the file with your students names.
lineup2.txt


Reading file lineup2.txt

The Number of people in the class is: 27
The first person in line is: Albert
The last person in line is: Zoey
Press any key to continue . . .



Enter the name of the file with your students names.
lineup3.txt


Reading file lineup3.txt

The Number of people in the class is: 12
The first person in line is: Blaine
The last person in line is: Xavier
Press any key to continue . . .



Enter the name of the file with your students names.
lineup4.txt


Reading file lineup4.txt

There is only one person in line
The first person in line is: Jack
Press any key to continue . . .



Enter the name of the file with your students names.
lineup5.txt


Reading file lineup5.txt

There is only one person in line
The first person in line is:
Press any key to continue . . .


Basically 1,2, 3, and 4 work fine. But 5 has no names so it should give the cout message saying there is no one in line. Please help!!
1
2
if (infile >> first) {
	infile >> first;
thank you, that fixed the problem.
Topic archived. No new replies allowed.