OK everyone, heres the deal.
i have the following code written.
what this program is supposed to do is read from a file "program6.txt".
in that file are lines of text in the following format:
"0 Jack Simpson 330 Maple Overton MO 64155"
the number preceeding the name ranges from 0-2, with 0 meaning that line is student info, 1 meaning teacher info, and 2 meaning staff info.
after reading from the file, the program is supposed to write all students to one text file, all teachers to another, and all staff to another. (creating 3 text files).
i have the program to where it can read in the information, and it determines the classification of each person, and even creates the output files, however, it does not place the information into those text files.
i cannot figure out why.
any help would be greatly appreciated
Zak
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void readFile(int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip);
void printStudent(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip);
void printTeacher(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip);
void printStaff(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip);
int main ()
{
int type, zip, houseNum;
string fName, lName, street, city, state;
readFile(type, fName, lName, houseNum, street, city, state, zip);
system("PAUSE");
return 0;
};
void readFile(int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip)
{
ifstream fin;
ofstream fout;
int count=0;
fin.open("program6.txt");
if(!fin)
{
cerr << "Error: file could not be opened" << endl;
system("PAUSE");
exit(1);
}
if(fin)
{
cout << "FILE OPENED" << endl;
}
do{
fin >> type >> fName >> lName >> houseNum >> street >> city >> state >> zip;
count++;
cout << count << endl;
if(type==0)
{
printStudent(count, type, fName, lName, houseNum, street, city, state, zip);
}
else if (type == 1)
{
printTeacher(count, type, fName, lName, houseNum, street, city, state, zip);
}
else if (type==2)
{
printStaff(count, type, fName, lName, houseNum, street, city, state, zip);
}
}while(!fin.eof());
fin.close();
fout.close();
cout << "End-of-file reached.." << endl;
system("PAUSE");
}
void printStudent(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip)
{
ofstream fout;
fout << "Students: " << endl << "First Name Last Name House Number Street"
<< " City State Zip" << endl;
fout.open("students.txt",ios::app);
fout << fName << lName << houseNum << street << city << state << zip << endl;
fout.close();
}
void printTeacher(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip)
{
ofstream fout;
fout << "Teachers: " << endl << "First Name Last Name House Number Street"
<< " City State Zip" << endl;
fout.open("teachers.txt",ios::app);
fout << fName << lName << houseNum << street << city << state << zip << endl;
fout.close();
}
void printStaff(int &count, int &type, string &fName, string &lName, int &houseNum, string &street, string &city, string &state, int &zip)
{
ofstream fout;
fout << "Staff: " << endl << "First Name Last Name House Number Street"
<< " City State Zip" << endl;
fout.open ("staff.txt",ios::app);
fout << fName << lName << houseNum << street << city << state << zip << endl;
fout.close();
}
</iomanip></string></fstream></iostream>
|