我正在尝试编写一个代码,通过使用eof()从文件中读取来计算注册费。但是,当我尝试编译时,我得到一个错误,即 C2677,这意味着二进制"-"未找到全局运算符。我已经研究了如何解决它,但我不明白。这是我的代码:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
string VIN, make, model, type, year;
string truck = "TRUCK";
double basefee, weight;
double tax = 0.065;
double highwayfund = 2.0;
int age;
double discount;
inFile.open("VehicleInput.txt");
outFile.open("VehicleOutput.txt");
while (!inFile.eof())
{
inFile >> VIN >> make >> model >> type >> year;
inFile >> weight;
age = (2020 - year);
weight = 12000;
discount = (age * 0.1);
if (age >= 7)
{
discount = 0.7;
}
if ((type == "CAR") || (type == "SUV"))
{
basefee = (100 - ((100.0 * tax) - (100 * discount)) + highwayfund);
}
if (type == "BUS")
{
basefee = (200 - ((200.0 * tax) - (200 * discount)) + highwayfund);
}
if (type == "TRUCK")
{
basefee = (500 - ((500.0 * (0.22 + tax)) - (500 * discount)) + highwayfund);
}
outFile << " " << VIN << " " << make << " " << model << " " << year;
if (weight > 12000) outFile << weight;
outFile << "$ " << basefee << endl;
}
return 0;
}
问题是这一行:
age = (2020 - year);
age
是一个int
.2020
是一个整数。year
声明为字符串。
string VIN, make, model, type, year;
int age;
这正是错误告诉您的。没有需要int
和string
operator-
.