hey guys, well i just want to get alittle help on something, so this is my prob, i finally got the first .txt files to be made by spereating them depending on there id numbers, which in short through each new employee is another new .txt file created, but the prob now is the directory.txt which i defined as dir, im trying to get whatever the user inputted to go not only onto the first filestream but as well as the directory.txt, (the directory serves as like the summary of all the new employees) but the prob is the directory file is made but xD it doesnt have any content, unlike the 1st files they all have the content of first name, last name etc, how can i resolve this?

int main()
{
    system("cls");
    string fname, mname, lname, fileName;
    double salary;
    int age, empId;


    cout << "PLEASE ENTER THE NEW EMPLOYEES FIRST NAME: ";

    cin >> fname;

    cout << "PLEASE ENTER THE NEW EMPLOYEES MIDDLE NAME: ";

    cin >> mname;

    cout << "PLEASE ENTER THE NEW EMPLOYEES LAST NAME: ";

    cin >> lname;

    cout << "PLEASE ETNER THE NEW EMPLOYEES AGE: ";

    cin >> age;

    cout << "PLEASE ENTER THE NEW EMPLOYEES SALARY: ";

    cin >> salary;

    cout << "PLEASE ENTER NEW EMPLOYEES ID NUMBER : ";

    cin >> empId;

    string empId2 = to_string(empId);
    empId2.append(".txt");

    ofstream newemployee(empId2);
    newemployee << fname << "\t\t" << mname << "\t\t" << lname << "\t\t" << empId << "\t" << salary << "\t" << age << endl;
    newemployee.close();

    ofstream dir("directory.txt", ios::app);
    newemployee << "FirstName \tMiddleName \tLastName \tID \tsalary \tage" << endl;
    newemployee << "___________________________________________________________________" << endl;
    newemployee << fname << "\t\t" << mname << "\t\t" << lname << "\t\t" << empId << "\t" << salary << "\t" << age << endl;
    dir.close();
    return 0;



}

Line 41 - 43 you output to the closed file newemployee instead of dir

Lines 41, 42 and 43 use the wrong file description. Should be dir, not newemployyee

[edit]Oope! I didn't see the above when I posted this. Sorry for duplicating the answer [/edit]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.