c++ - 包括“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();
};
解决方案
就我而言,问题在于我没有在项目中包含所有必要的库。对于拉脱维亚语言支持,我使用了库 lvtocon.h 和 lvtocon.cpp,但由于我的程序包含并且没有看到该文件,因此它不会成功运行。
将所有必要的文件添加到项目后,它编译成功。
推荐阅读
- javascript - React 聊天应用程序文本是长错误问题?
- c# - 在 MassTransit 中,是否可以拥有包含通用列表的合同的消费者?
- tensorflow - 维度必须相等,但节点 binary_crossentropy/mul 为 2 和 3
- apache - SearchError:在访问 Kibana 的 Apache 中请求实体太大
- php - 如何在 Laravel 中获取嵌套关系的实例?
- python - Python命令行安装窗口
- security - GCP 中 Windows 2016 服务器的 CIS 强化脚本
- functional-programming - Most efficient way to write big data structures to a file
- c# - 使用 XmlSerializer 向 xml 文件添加动态注释
- reactjs - 2checkout subscription 在 webhook 中发送订阅者的 UID