包括"lvtocon.h",未定义对'operator<<(std::ostream&, char const*)的引用

include "lvtocon.h", undefined reference to `operator<<(std::ostream&, char const*)

本文关键字:lt ostream char 引用 const operator 未定义 lvtocon 包括 std      更新时间:2023-10-16

使用C++(Codeblocks 17.12编译器(,每次程序在程序中看到"cout"时.cpp我一直收到这条消息。理想情况下,需要创建具有三个插入变量(fuel_amount、双fuel_consumption和双best_speed(的"GoodAuto"对象;能够用_change变量改变它们;能够删除该"GoodAuto"对象。

提前谢谢。

main.cpp
#include <iostream>
#include "program.h"
using namespace std;
int main(){
Auto GoodAuto(200, 5, 60);
}
program.cpp
#include "lvtocon.h"
#include <iostream>
#include "program.h"
using namespace std;
Auto::Auto(double fuel_amount, double fuel_consumption, double best_speed)
{
cout << "Enter fuel amount: " <<endl;
this->fuel_amount = (fuel_amount>=0)?fuel_amount: 10;
cout << "Enter fuel consumption for 100 km: " <<endl;
this->fuel_consumption = (fuel_consumption>0)?fuel_consumption: 1;
cout << "Enter optimal car speed: " <<endl;
this->best_speed = (best_speed>0)?best_speed: 120;
}
void Auto::Change(double fuel_amount_change, double fuel_consumption_change, double best_speed_change)
{
if (fuel_amount+fuel_amount_change>0) this->fuel_amount += fuel_amount_change; else fuel_amount = 0;
if (fuel_consumption+fuel_consumption_change>0) this->fuel_consumption += fuel_consumption_change; else fuel_consumption = 1;
if(best_speed + best_speed_change>0) this->best_speed += best_speed_change; else best_speed = 120;
}
void Auto::Print(){
cout << "Fuel amount = " << fuel_amount << " l."<< endl;
cout << "Fuel consumption for 100 km = " << fuel_consumption <<  " l/stunda." <<endl;
cout << "Auto optimal speed = " << best_speed <<" km/stunda."<<endl;
}
program.h   
class Auto                                                   
{
private:
double fuel_amount;
double fuel_consumption;
double best_speed;
public:
Auto(double fuel_amount, double fuel_consumption, double best_speed);
~Auto();
void Change(double fuel_amount_change, double fuel_consumption_change, double best_speed_change);
void Print();
};

就我而言,问题是我没有在项目中包含所有必要的库。 对于拉脱维亚语支持,我使用了库lvtocon.h和lvtocon.cpp,但由于我的程序包含并且没有看到该文件,因此它不会成功运行。

将所有必要的文件添加到项目中后,它成功编译。

你似乎没有实现你的析构函数。请尝试包含 ~A(( {} 的实现。