Created
October 13, 2013 01:03
-
-
Save anonymous/6956821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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