gpt4 book ai didi

c++ - 找不到 iostream 文件

转载 作者:行者123 更新时间:2023-11-28 05:22:25 28 4
gpt4 key购买 nike

我刚刚开始学习 C++ 的面向对象。在我的第一课中,我收到了错误 “找不到 iostream 文件”。我使用 Fedora 24 和 atom 编辑器进行编码。对于构建,我使用该命令 g++ main.cpp -o a 我还安装了 atom 的插件

gpp-compiler

我的主文件是:

#include <iostream>
#include <string>
#include "BMI.h"

using namespace std;

int main(){
string name;
int height;
double weight;

cout << "Enter your name: ";
cin >> name;

cout << "Enter your height (in inches): ";
cin >> height;

cout << "Enter your weight: ";
cin >> weight;
BMI a;
// BMI Student_1(name, height, weight);

return 0;
}

当我在没有 BMI 对象的情况下运行主文件时,它可以工作。但是当我在主函数中添加 BMI 对象时,输出是错误的。

我的 BMI 对象:头文件:

#include <iostream>
#include <string>

using namespace std;

#ifndef BMI_H
#define BMI_H

class BMI {
public:
//Default Constructor
BMI();
//Overload Constructor
BMI(string, int, double);
private:
//Member Variable
string newName;
int newHeight;
double newWeight;
};


#endif

CPP 文件:

#include "BMI.h"

BMI::BMI(){
newName = "aa";
newHeight = 0;
newHeight = 0.0;
}

BMI::BMI(string name, int height, double weight){
newName = name;
newHeight = height;
newWeight = weight;
}

本教程来自 https://www.youtube.com/watch?v=vz1O9nRyZaY

问题是为什么它不起作用,为什么它在没有 BMI 对象的情况下起作用?

谢谢,迈克尔。

最佳答案

您的 cpp 文件中有输入错误:

newHeight = 0;
newHeight = 0.0; // <- error

尝试:

newHeight = 0;
newWeight = 0.0;

关于c++ - 找不到 iostream 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41200135/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com