Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

File Reading and Writing

  1. Jul 6, 2008 #1
    Hi! Thanks for helping me. I need to write a program (in C++) that reads the file Employee.dat as input and then outputs to 4 different files which are Managers.dat, Marketing.dat, Developers.dat, and Testers.dat. Each of the output files contains the name of the employees of its category.

    The fle Employee.dat contains following data:

    Sue Leon 4
    Robert Wise 3
    Sam Woo 1
    Nathan White 3
    Suzan Head 2
    Henry Williams 4
    Christine Mint 1
    Kim Leeds 4
    Elton Sue 3
    Ken Latch 2

    I tried to write the program but I don't know what to put in "SWITCH" loop. Here is what i have so far.

    #include <iostrean>
    #include <fstream>
    #include <cstdlib>
    #include <string>
    using namespace std;

    int main()
    ifstream in_stream;
    ofstream out_stream;

    if (in_stream.fail())
    cout << "Input file failed to open.\n";

    out_stream.open(("Managers.dat", ios::app), ("Marketing.dat", ios::app), ("Developers.dat", ios::app), ("Testers.dat", ios::app);
    if (out_stream.fail())
    cout << "Output file failed to open.\n";

    string first_name, last_name;
    enum department { Managers = 1, Marketing = 2, Developers = 3, Testers = 4 };

    im_stream >> first_name >> last_name >> department;
    while (!in_stream.eof())
    switch (department)
    number '1';
    out_stream << "
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you help with the solution or looking for help too?
Draft saved Draft deleted