Reputation: 4731
I have just started to learn Object Oriented at C++.
In my first lesson I received that error "iostream file not found".
I use Fedora 24 and atom editor for coding.
For build I use that command g++ main.cpp -o a
I also installed atom's plugin
gpp-compiler
My main file is:
#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;
}
when I run main file without BMI object it works. But when I added BMI object in the main function the output is the error.
My BMI object: Header file:
#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 file:
#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;
}
This tutorial from https://www.youtube.com/watch?v=vz1O9nRyZaY
The question is why doesn't it work and why it works without BMI object?
Thanks, Michael.
Upvotes: 0
Views: 3289
Reputation: 390
You have typing error in your cpp file :
newHeight = 0;
newHeight = 0.0; // <- error
try :
newHeight = 0;
newWeight = 0.0;
Upvotes: 1