首页 > 解决方案 > 包括“lvtocon.h”,对 `operator<<(std::ostream&, char const*) 的未定义引用

问题描述

使用 C++(Codeblocks 17.12 编译器),每次程序在 program.cpp 中看到“cout”时,我都会收到此消息。理想情况下,需要使用三个插入变量(fuel_amount、doublefuel_consumption 和 double 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();
};

标签: c++codeblocks

解决方案


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

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


推荐阅读