输出文件显示不正确

时间:2019-03-17 20:09:45

标签: string class output fstream ifstream

我有一个项目,到目前为止,它已经可以工作了,除了当我尝试将输出写入.dat文件时,我不知道如何正确编码。输出是一个指针,该指针显示带有薪水的姓名,ssn和员工ID。我的头文件全部编码正确,但是在main.cpp中,我需要将输出打印到文件中。我对使用C ++进行编码有点陌生,但我仍然不了解写文件的所有基础知识。任何帮助,将不胜感激。谢谢

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();

0 个答案:

没有答案