Hi,

I installed Dev C++ on my PC ...its the first time I am using it.
Can somebody tell me how I can link and compile a .cpp and it's corresponding .h file to produce the required .exe ? I want to know how to build on Dev C++ basically.

Please help!

Recommended Answers

All 12 Replies

Create a project, open a new file in that project, write your program, press the compile and run button somewhere at the top and you are good to go. That's it !

Which step are you specifically stuck at?

Thanks for replying.

Well, let me explain what I have done:

created a project named P1 and then added to two files Sum.h and Sum.cpp to P1.

Sum.h is:

#ifndef SUM_H
#define SUM_H

class Sum {

public:
Sum(){}
~Sum(){}

int addInt(int a, int b);

};

#endif

Sum.cpp is:

#include<iostream.h>
#include<Sum.h>


int main()
{
cout<<"Welcome to main()"<<endl;
int a = 9;
int b = 1;
int result = 0;

result = Sum::addInt(a,b);

cout<<"Sum of a & b: "<<result<<endl;
getchar();
return 0;
}

int Sum::addInt(int a, int b)
{
int result=0;

result = a + b;

return 0;
}

Now I goto Execute->Compile and Run in the top menu .... it doesn't work at all ....it fails to recognise Sum or addInt ....

I'm missing something here ... please guide me.

sorry ... it is return result; not return 0 in Sum.cpp

Member Avatar for iamthwee

What happens if you change the #include<Sum.h> to #include"Sum.h"

And did you save #includeSum.h with the .h extension?

Hey ! thank u...I tried with "" and it worked ...
but have a doubt ...

when I first changed to "Sum.h" ....it began to recognize the method but it said cannot call addInt without an object ...so I created an obj and called it like this:

Sum obj;
result = obj.addInt(a,b);

...then it worked!!! ....but my doubt is: is it wrong to call using :: operator like

result = Sum::addInt(a,b);

???

plz clarify

Member Avatar for iamthwee

>plz clarify

Read your book.

And get a better one if it is telling you to use <iostream.h> since it may have outdated code examples as well.

Yeah using the .h is bad practice nowadays

>Yeah using the .h is bad practice nowadays
Is it? Only in the context of the STL...

Certain compilers throw up an error if you use it

>Certain compilers throw up an error if you use it
I've never seen a compiler that does that. When using the outdated STL headers, the most you'll get is a warning (because they can't completely wash out old C++ support).

thanks all for your inputs & assistance!

The .h form of header inclusion is still there for backward compatibility and there are many reason you shouldn't use them. This is what I got :

Although the <iostream.h> library was deprecated for several years, many C++ users still use it in new code instead of using the newer, standard compliant <iostream> library. What are the differences between the two? First, the .h notation of standard header files was deprecated more than 5 years ago. Using deprecated features in new code is never a good idea. In terms of functionality, <iostream> contains a set of templatized I/O classes which support both narrow and wide characters. By contrast, <iostream.h> classes are confined to char exclusively. Third, the C++ standard specification of iostream's interface was changed in many subtle aspects. Consequently, the interfaces and implementation of <iostream> differ from <iostream.h>. Finally, <iostream> components are declared in namespace std whereas <iostream.h> components are declared in the global scope. Because of these substantial differences, you cannot mix the two libraries in one program. As a rule, use <iostream> in new code and stick to <iostream.h> in legacy code that is incompatible with the new <iostream> library.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.