Выходной файл не отображается должным образом - PullRequest
0 голосов
/ 17 марта 2019

У меня есть проект, и я заставил его работать до сих пор, за исключением тех случаев, когда я пытаюсь записать вывод в файл .dat, я не могу понять, как правильно его кодировать. вывод - указатель, который печатает имя, ssn и идентификатор сотрудника с оплатой. У меня есть заголовочные файлы, все они закодированы правильно, но в main.cpp мне нужно распечатать вывод в файл. Я немного новичок в программировании на С ++, и я до сих пор не понимаю всех основ записи в файл. Любая помощь будет оценена. спасибо

include "HourlyPay.h"
include <string>
include <cctype>
include <iostream>
include <fstream>
include <iomanip>

using namespace std;

void PrintCheck(HourlyPay);

int main()
{

//When child classes are complete replace "Employee" with child class name.
HourlyPay employee1;
string firstName, lastName, ssn, empID;
float anPay, hours, rate;

HourlyPay *emp1 = nullptr;

emp1 = &employee1;

//prompt the user for their name. This section can remain the same.
cout << "Enter first name: ";
cin >> firstName;
cout << "\nEnter last name: ";
cin >> lastName;
cout << "\n\n";
employee1.SetName(firstName, lastName);

//prompt the user for their social security #

do
{
    cout << "Social Security Number must meet the following format:\n\tMust be in the xxx-xx-xxxx format.\n\t\tX is a digit 0-9 and '-' after third and fifth digit.\n\nEnter your Social Security Number:";
    cin >> ssn;
} while (employee1.SetSocial(ssn) != true);

//prompt the user for their employee id
do
{
    cout << "Employee Number must meet the following criteria:\n\tMust be in the xxx-L format.\n\t\tX is a digit 0-9 and L is a letter from A - M.\nEnter your Employee Number:";
    cin >> empID;
} while (employee1.SetEmployeeID(empID) != true);

//Perhaps prompt the user for additional details such as hourly pay, have conditional statements in function definition.
cout << "What is the employees' annual pay? ";
cin >> anPay;

employee1.setAnnualPay(anPay);
employee1.setHourlyRate();

cout << "Set hours worked: ";
cin >> hours;

employee1.setHoursWorked(hours);

//Display Employee info, be sure to redefine in child classes by calling the function from next level up in the hierarchy and adding onto it the same way we did it in the DetailedTime class.
PrintCheck(*emp1);

ofstream myfile;
myfile.open("pay.dat");
myfile << ??????; <---- IDK how to code this section
myfile.close();

system("pause");
return 0;
}

void PrintCheck(HourlyPay emp1) {
emp1.DisplayEmployee();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...