#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
class InsurancePolicy
{
friend ostream& operator<<(ostream&, InsurancePolicy);
friend istream& operator>>(istream&, InsurancePolicy);
private:
int policy;
string name;
double value;
double premium;
};
ostream& operator<<(ostream& out, InsurancePolicy ins)
{
out << ins.policy << " " << ins.name << " " <<
ins.value << " " << ins.premium;
return out;
}
istream& operator>>(istream& in, InsurancePolicy ins) // the error shows up during this section
{
in >> ins.policy >> " " >> ins.name >> " " >>
ins.value >> " " >> ins.premium;
return in;
}
//I'm not sure why.
int _tmain(int argc, _TCHAR* argv[])
{
InsurancePolicy aPolicy;
ofstream outFile;
outFile.open("Insurance.dat");
cout << "Enter policy number, last name, value of policy and annual premium" << endl;
cout << "Enter end-of-file key comination to end";
while(cin >> aPolicy)
{
outFile << aPolicy << endl;
cout << "Enter policy number, last name, value of policy and annual premium" << endl;
cout << "enter end-of-file key comination to end";
}
outFile.close();
system("pause.exe");
return 0;
}
"InsurancePolicy" Istream operator error C2678
Page 1 of 13 Replies - 144 Views - Last Post: 21 November 2012 - 07:02 PM
#1
"InsurancePolicy" Istream operator error C2678
Posted 19 November 2012 - 05:06 PM
Hello, I have written the following in visual basic 2010 express and have been issued error C2678 for the in >> ins.policy section. I am confused as to why this is wrong. I have looked at other cases of this error but I haven't really seen a solution that fits my problem. If there is any further information that you need please ask.
Replies To: "InsurancePolicy" Istream operator error C2678
#2
Re: "InsurancePolicy" Istream operator error C2678
Posted 19 November 2012 - 05:29 PM
Look closely at the following snippet:
Now how can you accept input into a const string?
Jim
in >> ins.policy >> " " >>
Now how can you accept input into a const string?
Jim
#3
Re: "InsurancePolicy" Istream operator error C2678
Posted 21 November 2012 - 06:39 PM
jimblumberg, on 19 November 2012 - 05:29 PM, said:
Look closely at the following snippet:
Now how can you accept input into a const string?
Jim
in >> ins.policy >> " " >>
Now how can you accept input into a const string?
Jim
Thank you so much. It took me quite a while to figure out what you were asking me. You truly helped me here. The repaired code turned out making much more sense. I hadn't even realized that I had added those quotation marks, I was blindly using the ostream as a template without thinking. You actually replied and helped before my instructor.
in >> ins.policy >> ins.name >> ins.value >> ins.premium; return in;
#4
Re: "InsurancePolicy" Istream operator error C2678
Posted 21 November 2012 - 07:02 PM
Glad you figured it out. Sometimes the simplest mistakes are the hardest to find.
In the future if you have compile errors, post the complete error message. These messages have important information to aid in locating and fixing the problem. One of the items in the message is the line number where the compiler detected the error.
Jim
In the future if you have compile errors, post the complete error message. These messages have important information to aid in locating and fixing the problem. One of the items in the message is the line number where the compiler detected the error.
Jim
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|