3 Replies - 273 Views - Last Post: 21 November 2012 - 07:02 PM Rate Topic: -----

#1 CaptKodyTyler  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-November 12

"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.

#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;
}



Is This A Good Question/Topic? 0
  • +

Replies To: "InsurancePolicy" Istream operator error C2678

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4027
  • View blog
  • Posts: 12,434
  • Joined: 25-December 09

Re: "InsurancePolicy" Istream operator error C2678

Posted 19 November 2012 - 05:29 PM

Look closely at the following snippet:

 in >> ins.policy >> " " >>


Now how can you accept input into a const string?

Jim
Was This Post Helpful? 1
  • +
  • -

#3 CaptKodyTyler  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-November 12

Re: "InsurancePolicy" Istream operator error C2678

Posted 21 November 2012 - 06:39 PM

View Postjimblumberg, on 19 November 2012 - 05:29 PM, said:

Look closely at the following snippet:

 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;

Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4027
  • View blog
  • Posts: 12,434
  • Joined: 25-December 09

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1