#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
class InsurancePolicy
{
friend fstream& operator<<(fstream&, InsurancePolicy);
friend istream& operator>>(istream&, InsurancePolicy&);
private:
int policyNum;
string lastName;
int value;
int premium;
};
fstream& operator<<(fstream& out, InsurancePolicy pol)
{
out << pol.policyNum << " " << pol.lastName << " " << pol.value << " " << pol.premium << endl;
return out;
}
istream& operator>>(istream& in, InsurancePolicy& pol)
{
in >> pol.policyNum >> pol.lastName >> pol.value >> pol.premium;
return in;
}
int main()
{
ofstream outfile;
outFile.open("Policy.txt");
Policy aPolicy[10];
for (int count = 0; count < 10; ++count)
{
printf("Enter the policy number, the holder's last name, the value, and the premium.");
cin >> aPolicy[count];
outfile << aPolicy[count] << endl;
}
} This program should accept values from the keyboard and print them into a file. However, it is giving a bunch of syntax errors.
Severity Code Description Project File Line Suppression State Error C2065 'outFile': undeclared identifier Project6 c:\users\preston freeman\source\repos\jave.cpp 39
Error C2228 left of '.open' must have class/struct/union Project6 c:\users\preston freeman\source\repos\jave.cpp 39
Error C2065 'Policy': undeclared identifier Project6 c:\users\preston freeman\source\repos\jave.cpp 40
Error C2146 syntax error: missing ';' before identifier 'aPolicy' Project6 c:\users\preston freeman\source\repos\jave.cpp 40
Error C2065 'aPolicy': undeclared identifier Project6 c:\users\preston freeman\source\repos\jave.cpp 40
Error C2065 'aPolicy': undeclared identifier Project6 c:\users\preston freeman\source\repos\jave.cpp 44
Error C2065 'aPolicy': undeclared identifier Project6 c:\users\preston freeman\source\repos\jave.cpp 45
How do I fix these errors? thank you for your time?
outfile
andoutFile
; alsoPolicy
andInsurancePolicy
. – Sam Varshavchikfriend fstream& operator<<(fstream&, InsurancePolicy);
-- This should be:friend fstream& operator<<(fstream&, const InsurancePolicy&);
. You should not be passing objects by value to an output streaming function. – PaulMcKenzie