簡體   English   中英

包括“lvtocon.h”,對`operator<<(std::ostream&, char const*)的未定義引用

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

使用 C++(Codeblocks 17.12 編譯器),每次程序在 program.cpp 中看到“cout”時,我都會收到此消息。 理想情況下需要創建帶有三個插入變量(fuel_amount、double fuel_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();
};

就我而言,問題是我沒有在項目中包含所有必要的庫。 對於拉脫維亞語支持,我使用了庫 lvtocon.h 和 lvtocon.cpp,但由於我的程序包含但未看到該文件,因此無法成功運行。

將所有必要的文件添加到項目后,它編譯成功。

你似乎沒有實現你的析構函數。 請嘗試包含 ~A() {} 的實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM