[英]Problems converting from printf scanf to cin cout
For my homework assignment I have been been asked to take my previous project and change it from using <stdio.h>
to <iostream>
In the process I've had quite a few errors, and am just a little stuck on a few particular ones. 在执行家庭作业时,我被要求接受我以前的项目,并将其从使用<stdio.h>
更改为<iostream>
在此过程中,我遇到了很多错误,并且在某些特定的问题上有一些卡住那些。
As far as my preprocessor directives go, I have included: 就我的预处理程序指令而言,我包括:
#include <iostream>
#include <iomanip>
#include <fstream>
the error codes I have gotten specify specific lines of my code. 我得到的错误代码指定了代码的特定行。 One of the recurring errors I get is: 我遇到的经常性错误之一是:
error: expected primary-expression before âfloatâ
This error came from these lines: 该错误来自以下行:
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;
}
This is one of my external functions. 这是我的外部功能之一。 The error code occurs several times with my other functions. 我的其他功能多次出现错误代码。 I figure that the issue is similar to what ever is causing this one. 我认为这个问题与导致这一问题的原因相似。 If anyone could help point me in the right direction that would be great! 如果有人可以帮助我指出正确的方向,那就太好了!
-Devin 戴文
What type is reportfile
? 是什么类型reportfile
? The comma between reportfile
and the \\n\\nAverages:
string looks odd - shouldn't that be a <<
also? reportfile
和\\n\\nAverages:
字符串之间的逗号看起来很奇怪-也应该不是<<
吗?
You'll want spaces between your floats, otherwise it will all run together. 在浮动对象之间需要空格,否则它们将一起运行。 Use << " " <<
between each float
instead of just <<
. 在每个float
之间使用<< " " <<
而不是<<
。
Try 尝试
std::ofstream
as ofstream is declared in namespace std. asofstream在名称空间std中声明。
Also the comma after reportfile should be a <<
. 报告文件后的逗号也应为<<
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.