anonymous / gist:6956821
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:6956821
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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
 
int main()
{
 
// Variable Declarations
ifstream infile;
ofstream outfile;
int numStudents = 0;
string filename;
string studentName;
string firstStudent;
string lastStudent;
 
// Ask user for name of file, open and test file.
cout << "Enter the name of the file with your student's names.\n";
cin >> filename;
cout << endl;
infile.open(filename.c_str());
 
if (infile.fail())
{
cout << "Sorry, file " << filename << " was not found.\n";
cout << "\nEnding program...\n\n";
return 1;
}
 
// File is open for reading.
cout << "Reading file " << filename << endl;
 
if (infile >> studentName )
{
studentName = firstStudent = lastStudent;
while ( infile >> studentName )
{
cout << studentName << endl;
numStudents++;
}
cout << "There are " << numStudents << " students in line" << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.