我正在学习 C++。我在格式化程序的输出时遇到问题。我想在那里打印完全对齐的列,但到目前为止我做不到,这是我的代码:
int main()
{
employee employees[5];
employees[0].setEmployee("Stone", 35.75, 053);
employees[1].setEmployee("Rubble", 12, 163);
employees[2].setEmployee("Flintstone", 15.75, 97);
employees[3].setEmployee("Pebble", 10.25, 104);
employees[4].setEmployee("Rockwall", 22.75, 15);
printEmployees(employees, 5);
return 0;
}
// print the employees in my array
void printEmployees(employee employees[], int number)
{
int i;
for (i=0; i<number; i++) {
employees[i].printEmployee();// this is the method that give me problems
}
cout << "\n";
}
在类员工中,我有打印员工方法:
void printEmployee() const
{
cout << fixed;
cout << surname << setw(10) << empNumber << "\t" << setw(4) << hourlyRate << "\n";
}
问题是当我打印“flinstones”行时,emp 编号和 rate 没有对齐。发生这样的事情:
斯通 43 35.750000 碎石 163 12.000000 燧石 97 15.750000 鹅卵石 104 10.250000 罗克沃尔 15 22.750000
有谁能够帮助我?(我试图添加标签..但它没有帮助)