Click here to Skip to main content
15,904,500 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: You're welcome Pin
NewVC++7-Dec-08 21:01
NewVC++7-Dec-08 21:01 
GeneralRe: You're welcome Pin
Hamid_RT7-Dec-08 21:28
Hamid_RT7-Dec-08 21:28 
QuestionHow to ownerdraw a scrollbar inside a listbox? Pin
KellyR7-Dec-08 17:54
KellyR7-Dec-08 17:54 
AnswerRe: How to ownerdraw a scrollbar inside a listbox? Pin
Hamid_RT7-Dec-08 18:24
Hamid_RT7-Dec-08 18:24 
QuestionRe: How to ownerdraw a scrollbar inside a listbox? Pin
KellyR7-Dec-08 18:28
KellyR7-Dec-08 18:28 
AnswerRe: How to ownerdraw a scrollbar inside a listbox? Pin
Nishad S7-Dec-08 22:04
Nishad S7-Dec-08 22:04 
GeneralRe: How to ownerdraw a scrollbar inside a listbox? Pin
KellyR8-Dec-08 16:00
KellyR8-Dec-08 16:00 
QuestionNeeding help with finishing a program Pin
Zak Forlow7-Dec-08 16:03
Zak Forlow7-Dec-08 16:03 
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; // fin is like cin
    ofstream fout; //fout is like cout
    int count=0;
    
    fin.open("program6.txt"); // opens the file
    if(!fin)
    { // file couldn't be opened
        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)
        {
            //fout.open ("students.txt",ios::app);
         printStudent(count, type, fName, lName, houseNum, street, city, state, zip);

        }
        else if (type == 1)
        {
            //fout.open("teachers.txt",ios::app);
            printTeacher(count, type, fName, lName, houseNum, street, city, state, zip);
   
        }
        else if (type==2)
        {
            //fout.open("staff.txt",ios::app);
            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 is like cout

        

        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 is like cout

        //

        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 is like cout

        

        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>

AnswerRe: Needing help with finishing a program Pin
Member 41945937-Dec-08 16:44
Member 41945937-Dec-08 16:44 
AnswerRe: Needing help with finishing a program Pin
David Crow8-Dec-08 4:06
David Crow8-Dec-08 4:06 
QuestionAre std::list std::vector std::map thread-safe class? Pin
fantasy12157-Dec-08 15:25
fantasy12157-Dec-08 15:25 
AnswerRe: Are std::list std::vector std::map thread-safe class? Pin
Randor 7-Dec-08 17:43
professional Randor 7-Dec-08 17:43 
GeneralRe: Are std::list std::vector std::map thread-safe class? Pin
fantasy12158-Dec-08 4:14
fantasy12158-Dec-08 4:14 
QuestionLinking Error using GLUI ('MSVCRT' conflicts with use of other libs) Pin
LostPitch7-Dec-08 9:42
LostPitch7-Dec-08 9:42 
AnswerRe: Linking Error using GLUI ('MSVCRT' conflicts with use of other libs) Pin
Jijo.Raj7-Dec-08 10:24
Jijo.Raj7-Dec-08 10:24 
GeneralRe: Linking Error using GLUI ('MSVCRT' conflicts with use of other libs) Pin
LostPitch7-Dec-08 14:11
LostPitch7-Dec-08 14:11 
QuestionRe: Linking Error using GLUI ('MSVCRT' conflicts with use of other libs) Pin
Randor 7-Dec-08 17:48
professional Randor 7-Dec-08 17:48 
AnswerRe: Linking Error using GLUI ('MSVCRT' conflicts with use of other libs) Pin
LostPitch8-Dec-08 2:18
LostPitch8-Dec-08 2:18 
GeneralRe: Linking Error using GLUI ('MSVCRT' conflicts with use of other libs) Pin
LostPitch8-Feb-09 5:34
LostPitch8-Feb-09 5:34 
QuestionBlock windows key Pin
dj44007-Dec-08 1:30
dj44007-Dec-08 1:30 
AnswerRe: Block windows key Pin
Code-o-mat7-Dec-08 1:43
Code-o-mat7-Dec-08 1:43 
QuestionScroll Bar Position Control Pin
Shivbalaji6-Dec-08 23:30
Shivbalaji6-Dec-08 23:30 
AnswerRe: Scroll Bar Position Control Pin
Graham Shanks7-Dec-08 11:21
Graham Shanks7-Dec-08 11:21 
GeneralRe: Scroll Bar Position Control Pin
Member 46517417-Dec-08 21:54
Member 46517417-Dec-08 21:54 
QuestionFind position of first occurrence of a case-insensitive string int stripos ( char* haystack, char* needle, int offset ) Pin
wizardzaw6-Dec-08 22:16
wizardzaw6-Dec-08 22:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.