【发布时间】:2018-04-21 02:50:11
【问题描述】:
#include <iostream>
#include <fstream>
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, const 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");
InsurancePolicy 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;
}
return 0;
}
由于以下错误,该程序将无法编译: 严重性 代码 描述 项目 文件 线 抑制状态 错误 C2679 二进制“>>”:未找到采用“std::string”类型右侧操作数的运算符(或没有可接受的转换) 项目6 c:\users\preston freeman\source\repos\jave.cpp 21
错误 C2679 二进制“
错误 C2679 二进制“
如何解决这些错误? 感谢您的宝贵时间。
【问题讨论】:
-
常规重载在
ostream,而不是fstream。并再次检查您的函数原型。
标签: c++