Skip to content

Instantly share code, notes, and snippets.

Created October 13, 2013 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6957443 to your computer and use it in GitHub Desktop.
Save anonymous/6957443 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
// Variable Declarations
ifstream infile;
ofstream outfile;
int numStudents=0;
string filename;
string studetName;
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<<"Unable to open file"<<endl;
}
else
{
while(infile>>studetName)
{
if(numStudents==0)
{
firstStudent=studetName;
}
lastStudent=studetName;
numStudents++;
}
cout<<"Total Students: "<<numStudents<<endl;
cout<<"First student in line: "<<firstStudent<<endl;
cout<<"Last student in line : "<<lastStudent<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment