我刚刚开始在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;
};
#endifCPP文件:
#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的物体工作呢?
谢谢,迈克尔。
发布于 2016-12-17 16:21:04
您的cpp文件中有键入错误:
newHeight = 0;
newHeight = 0.0; // <- error试着:
newHeight = 0;
newWeight = 0.0;https://stackoverflow.com/questions/41200135
复制相似问题