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.
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
? The comma between reportfile
and the \\n\\nAverages:
string looks odd - shouldn't that be a <<
also?
You'll want spaces between your floats, otherwise it will all run together. Use << " " <<
between each float
instead of just <<
.
Try
std::ofstream
as ofstream is declared in namespace std.
Also the comma after reportfile should be a <<
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.