-4
我是C++的新手,我有我的第一个任务。我们有一个文本文件,其中包含5个员工姓名,工资和工作时间。如何将项目添加到输出文件?
这是我的代码,以便我的程序可以读取它。
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
int main()
{
ifstream input;
ofstream output;
string name;
int h;
float w;
int numEployee = 0;
double maxPay, minPay, avgPay;
int gross, adjGross;
//input/output file document path
input.open("/Users/jmduller/Documents/xcode/Lab1/Lab1/Employees.txt");
output.open("/Users/jmduller/Documents/xcode/Lab1/Lab1/Employeesoutput.txt");
//checks if the input file is working
if (input.fail())
{
cout << "Input file failed to open." << endl;
system("pause");
exit(0);
}
//checks if output file is working
if (output.fail())
{
cout << "Output file failed to open." << endl;
system("pause");
exit(0);
}
//prints the name, wage, hours worked of the employees to the output file
while (input >> name >> w >> h)
{
output << setw(5) << name << setw(5) << w << setw(5) << h << endl;
}
system("pause");
return 0;
}
它正确地阅读它,并给我输出文件,我想要但缺少项目。完整的输出文件应该有员工人数,最高工资,最低工资,平均工资,总工资和调整总额。
任何人都可以帮助我指向正确的方向吗?
感谢
以下是您需要创建[mcve]的说明。只要问问自己以下问题:有人可以拿出你在问题中提供的所有信息,并自己重现你的问题吗?如果不是,那么你的问题不能满足[mcve]的所有要求。 –
好吧,你的'while'循环读取3个标记并将它们传递给输出文件。你为什么期望别的什么东西在那里?你提到**平均工资** - 你在哪里计算它? – Fureeish
您正在努力编写任何信息。你有一个评论,说它有,但你没有添加到该块的代码。如果你这样做,你不会再有问题了。我们没有为你做功课。如果您希望在输出中使用这些项目,请更改代码以包含它们。 –