我需要编写一个作业分配程序来计算学费,并且输出的格式应与美元符号后的点填充和空格填充类似:Student Name: Name goes hereAddress: Address goes hereNumber of credits: .......... 5Cost per credit hour: ............ $ 50到目前为止,我的代码是:#include <iostream>#include <iomanip>#include <string>#include <fstream>using namespace std;double const REG_FEE = 700, STUDENT_ASSEMBLY_FEE = 7.19, LEGAL_FEE = 8.50, STUDGOV_FEE = 1.50,LATE_FEE_PERCENTAGE = 0.015;int main(){ double num_credits, cost_per_credit, tuition_total, late_charge, amount_due;string student_name;string student_address;string student_city_state_ZIP;ifstream info;info.open ("info.txt");getline (info, student_name);getline (info, student_address);getline (info, student_city_state_ZIP);info >> num_credits;info >> cost_per_credit;tuition_total = num_credits * cost_per_credit + REG_FEE + STUDENT_ASSEMBLY_FEE + LEGAL_FEE+ STUDGOV_FEE;late_charge = tuition_total * LATE_FEE_PERCENTAGE;amount_due = tuition_total + late_charge;cout << "Tuition and Billing Program by Neal P." << endl<< setw(18) << "Student Name:" << student_name << endl<< setw(18) << "Address:" << student_address << endl<< left << setfill('.') << endl<< setfill(18) << "Number of Credits:" << setw(5) << "$" << num_credits << endl<< setfill(18) << "Cost per Credit Hour:" << setw(5) << "$" << cost_per_credit << endl<< setfill(18) << "Tuition Cost:" << setw(5) << "$" << tuition_total << endl<< setfill(18) << "Registration Fee:" << setw(5) << "$" << REG_FEE << endl<< setfill(18) << "MSA Fee:" << setw(5) << "$" << STUDENT_ASSEMBLY_FEE << endl<< setfill(18) << "Legal Services Fee:" << setw(5) << "$" << LEGAL_FEE << endl<< setfill(18) << "Student Government Fee:" << setw(5) << "$" << STUDGOV_FEE << endl;return 0;}当我编译时,我得到了一个很长的错误,类似于:“在函数'int main()'中:/ Users / nealp / Desktop / machine问题2.cpp:41:错误:'(((std :: basic_ostream> *)std :: operator &)((std :: basic_ostream> *)((std :: basic_ostream> *)((std :: basic_ostream> *)std :: operator 我同时使用setw和setfill是否有问题?我知道setfill只需要声明一次,并且setw仅对下一行输出有效,但是我每次都定义setfill是因为我之前使用过setw。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 std::setfill是function template,它的模板参数根据传递给它的参数的类型推导出。它的返回类型是不确定的-它是一些实现定义的代理类型,它在流对象上设置填充字符并允许进一步链接operator<<调用。它还取决于setfill实例化的类型。文字18的类型为int,因此setfill返回一些不相关的类型,而operator<<不可用。我不确定您对setfill(18)的含义,我猜您将其误认为setw(18)。 (adsbygoogle = window.adsbygoogle || []).push({});
10-08 13:28