[英]Problems converting from printf scanf to cin cout
在執行家庭作業時,我被要求接受我以前的項目,並將其從使用<stdio.h>
更改為<iostream>
在此過程中,我遇到了很多錯誤,並且在某些特定的問題上有一些卡住那些。
就我的預處理程序指令而言,我包括:
#include <iostream>
#include <iomanip>
#include <fstream>
我得到的錯誤代碼指定了代碼的特定行。 我遇到的經常性錯誤之一是:
error: expected primary-expression before âfloatâ
該錯誤來自以下行:
void PrintAverages(ofstream &output, int tot_employees, float tot_payrate, float tot_reghrs,
float tot_ovthrs, float tot_gross, float tot_fed, float tot_state,
float tot_ssi, float tot_def, float tot_net)
{
output << reportfile, "\n\nAverages:" << tot_payrate / tot_employees <<
tot_reghrs / tot_employees << tot_gross / tot_employees <<
tot_fed / tot_employees << tot_ssi / tot_employees << tot_net / tot_employees <<
tot_ovthrs / tot_employees << tot_state / tot_employees << tot_def / tot_employees;
}
這是我的外部功能之一。 我的其他功能多次出現錯誤代碼。 我認為這個問題與導致這一問題的原因相似。 如果有人可以幫助我指出正確的方向,那就太好了!
戴文
是什么類型reportfile
? reportfile
和\\n\\nAverages:
字符串之間的逗號看起來很奇怪-也應該不是<<
嗎?
在浮動對象之間需要空格,否則它們將一起運行。 在每個float
之間使用<< " " <<
而不是<<
。
嘗試
std::ofstream
asofstream在名稱空間std中聲明。
報告文件后的逗號也應為<<
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.