HELP infile and functions

I was assigned a project to prompt the user for an infile name and it is supposed to spit the output of said file. It also requires the use of functions. This is what I have so far:

(the A3.txt is the file I am attempting to open)


#include<iostream>
#include <string>
#include<fstream>
#include <iomanip>


using namespace std ;



void file_reader(ifstream& infile,int&count);
void name_printer( string firstname, string lastname);

int main()
{
int count;
ifstream infile;

cout << "Please enter the input file name: " ;
while (true)
{
string infilename;
getline( cin, infilename );
infile.open( infilename.c_str() );
if (infile) break;
cout << "Invalid file." << endl;
}
count=0;

infile.open("A3.txt");

file_reader(infile,count);
infile.close ();


return 0;

}




void file_reader(ifstream& infile,int&count)

{

string lastname,firstname,officebuilding;
int districtnumber,roomnumber;
string party;

infile>>districtnumber>>firstname>>lastname>>party>>officebuilding>>roomnumber;
cout << left << setw(10) << "Dist.#" << left << setw(10)<< "Name" << left << setw(15) << "Party" << left << setw(10) << "Office" << left << setw(12) << "Room #" << endl;
cout << left << setw(10) << "======" << left << setw(10) << "====" << left << setw(15) << "=====" << left << setw(10) << "======" << left << setw(12) << "=======" << endl;


cout << left << setw(25);
cout<< left << setw(5) << districtnumber;
name_printer(firstname,lastname);
cout << left << setw(5) <<party << left << setw(15) << officebuilding << left << setw(7) << roomnumber;



infile>>districtnumber>>firstname>>lastname>>party>>officebuilding>>roomnumber;
}

void name_printer( string firstname, string lastname)
{

cout << lastname +", "+ firstname;

}
Topic archived. No new replies allowed.