Object Class in C++

I need help on how to run code with (#include "Rectangle.h") in Dev-C++ IDE. Every time I try to run the code below with Dev-C++ or online GDB, I keep getting compilation termination notice (Error ) Rectangle.h: No file or directory.

I like using Dev-C++ IDE, how can have my IDE recognize this directory? Eclipse and Virtual Studio always hang my computer that is why I don't use them.

Below is the code:

// This program demonstrates memberwise assignment.

#include <iostream>
#include "Rectangle.h"
using namespace std;

int main ()
{

// Define two Rectangle objects.

Rectangle box1 (10.0, 10.0); // width =10.0, length =10.0
Rectangle box2 (20.0, 20.0); // width= 20.0, length =20.0
// Display each object's width and length.
cout << "box1's width and length: "<< box1.getWidth()
<<" "<< box1.getLength() << endl;
cout << "box2's width and length: " << box2.getWidth()<< " " <<
box2.getLength() << endl <<endl;

// Assign the members of box1 to box2.
box2=box1;

// Display each object's width and length again.
cout << "box1's width and length: " << box1.getWidth () << " "
<< box1.getLength() << endl;
cout << "box2's width and length: " << box2.getWidth ()
<<" " << box2.getLength() << endl;

return 0;
}

Hello Keked10,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



The short answer is when a header file is in double quotes it needs to be in the same directory as the ".cpp" file that is loading it. The other alternative is to use a path to the file if needed.

Hope that helps,

Andy
Handy Andy wrote:
The short answer is when a header file is in double quotes it needs to be in the same directory as the ".cpp" file that is loading it.

Nonsense. The header file can be in any of the directories that is specified as part of the include path.

@Keked10 You need to find out what directory your Rectangle.h file is in, and make sure you're telling the compiler to look for include files in that directory.
#include "..." adds the directory of the current file to the search directories. The compiler searches for the header in the 'current' directory first. If the file is not found then it behaves like #include <...> which is looking into the specified directories.
@MikeyBoy,

Its not "nonsense". coder777 has taken these two links:
https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename
https://developerinsider.co/what-is-the-difference-between-include-filename-and-include-filename/ and condensed what they are saying.

That is why I called it the short answer because I could not put the time into explaining everything then and was hoping for a response from OP to see what I needed to expand on.

Andy
It is nonsense to say the Rectangle.h header file needs to be in the same directory as the OP's source. That is an outright lie.

It would have been perfectly possible to express, simply and clearly, the idea that putting the header file into the same directory would enable the compiler to find it, without saying something that is factually untrue.

Don't say things to beginners that aren't true. They might end up believing you, causing them problems down the line.
Last edited on
The IDE i use is Dev-C++, how do i put the Rectangle.h header file into its directory. i have checked both the save location and the app download location but i do not know how to put the header file into a directory, I need help please, remember i am still a beginner.
1) Do you know what directory your Rectangle.h file is currently in? If not, use the tools in your operating system to find the file.

2) In your IDE, modify the settings in your project to add that directory to the include path.
Topic archived. No new replies allowed.