包括"lvtocon.h",未定义对'operator<<(std::ostream&, char const*)的引用
include "lvtocon.h", undefined reference to `operator<<(std::ostream&, char const*)
使用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(( {} 的实现。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- ostream过载时的缓冲区冲洗
- 需要从 istream 和 ostream 派生 iostream
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- "ostream &os"有什么用?
- 为什么常量词在重载运算符中不与 ostream 对象一起使用<<?
- 我的运算符重载是否有效<<(流插入)左操作数不是 ostream
- C++表达SFINAE和ostream操纵器
- 在抛出 'std::runtime_error' 的实例后终止调用 what(): Filebuf 和 ostream 的 I/O 错误
- oStream 不打印添加两个 valarray 的结果(使用运算符重载)
- C++运算符<<调用::ostream而不是std::osttream
- BOOST ::变体无法解决运算符&lt;&lt;对于STD :: Ostream
- C++ostream:没有运算符匹配<<&应在'&'代币
- 重载运算符<<用于ostream语法
- 重载ostream&时转换错误无效;operator< & lt;
- 运算符<<(ostream&os,..)用于模板类
- std::ostream&operator< & lt; (std:: ostream&压力,压力& &;val)
- 上Ostream & lt; & lt;重载的困惑