0

我想知道当我尝试编译我的代码时,是否有人可以告诉我这些错误消息的含义。

这是我得到的错误:
in function 'int main()': not match for 'operator<<'in 'std::operator<<[with_Traits = std::char_traits(((std::basic_ostr ...

它会重复一段时间。

我想发布我的完整代码,以便您了解我的任务是什么,它不会那么长!=)

#include <iostream>
#include <cstdlib>
using namespace std;

class Odometer

{
public:

Odometer();

void reset();
void totalfuel();

void input_miles(int getmiles);
void Odometer::set_fuel_efficiency(double fuel_efficiency);

int gallonsUsed;

private:
int milesDriven;
double fuel_efficiency;
int getmiles;   
};

Odometer::Odometer()
{   
milesDriven = 0;
fuel_efficiency = 0;    
}

void Odometer::reset()
{
milesDriven = 0;
}

void Odometer::totalfuel()
{
fuel_efficiency = (milesDriven/gallonsUsed);
}

void Odometer::input_miles(int miles_driven)
{
milesDriven = milesDriven + miles_driven;

}

void Odometer::set_fuel_efficiency(double Fuel_efficiency)
{
fuel_efficiency = Fuel_efficiency;
}

double Odometer::getgallons()
{
return milesDriven/fuel_efficiency;
} 

// ======================
// main function
// ======================
int main()
{
// Two test trips
Odometer trip1, trip2;

trip1.reset();
trip1.set_fuel_efficiency(45);
trip1.input_miles(100);
cout << "For your fuel-efficient small car:" << endl;
cout << "After 100 miles, " << trip1.totalfuel() << " gallons used." << endl;
trip1.input_miles(50);
cout << "After another 50 miles, " << trip1.totalfuel() << " gallons used." << endl;

trip2.reset();
trip2.set_fuel_efficiency(13);
trip2.input_miles(100);
cout << "For your gas guzzler:" << endl;
cout << "After 100 miles, " << trip2.totalfuel() << " gallons used." << endl;
trip2.input_miles(50);
cout << "After another 50 miles, " << trip2.totalfuel() << " gallons used." << endl;

system("PAUSE");
return 0;
}
4

2 回答 2

4

您希望cout << void打印什么?

totalfuel()返回void,并且您将其作为参数传递给cout::operator <<. 你的意思是从方法中返回一些东西吗?

也许:

double Odometer::totalfuel()
{
    fuel_efficiency = (milesDriven/gallonsUsed);
    return fuel_efficiency;
}
于 2012-12-06T22:18:14.903 回答
3

totalFuel()返回无效。我认为您的意思是调用该getgallons()方法。

于 2012-12-06T22:20:14.280 回答