Site icon Learn C++

How To Compile And Run A C++ Program

How To Compile And Run A C++ Program

C++ is one of the most powerful programming languages and it’s suitable for a wide variety of uses. The RAD Studio, C++ Builder IDE is a simple development tool for those who want to develop a C++ applications. Using a fast and reliable C++ IDE is very important for beginners and professionals alike since it developers in remembering which language features exist, how to use them, and even detect errors when we get them wrong. Although C++ definitely rules the charts now, the C language is still very popular among developers. Embarcadero Dev-C++ is free, and is a fast, portable and simple C/C++ IDE for Windows.

The free version of C++ Builder CE is also great for beginners. If you want to develop professionally it is highly recommended you start with C++ Builder CE version. Today we have a great selection to choose from when looking for a free C++ IDE. Tools like C++ Builder CEDev-C++, and even the BCC32 command line compiler.

In this post, we will explain How To Compile And Run A C++ Program with the Dev-C++, with the C++ Builder CE, and with the C++ Builder professionally.

How to compile and run a C++ Program with Dev-C++?

You can use Dev-C++ to develop small C++ applications and you can compile and run them easily. If you don’t have Dev-C++, you can read the article below which tells you how to download and install Dev-C++ ready for your first project.

If you installed Dev-C++ then we can start to code,

  1. Create a new Project in Dev-C++
  2. We can start coding with very simple code, for example we can start with Hello World example.

If you are new to C++ programming, here is a quick introduction to create a simple C Program. C programs are simple text files, which means you can use any editor to edit these kind of programs, but a proper C++ IDE has much more features.

When you start coding, first of all, you should include libraries that you wish to use. The C++ language has many libraries and each of them has commands or functions for specific tasks. For example, the iostream library has standard input and output methods to display data and read from files and similar sources. Generally, for beginners, the iostream header is enough to enable you to create simple apps. We can include this library header as below,

[crayon-67634a4bdf0f4319160871/]

Second, you should add a main procedure. This is the main part of the program – hence the name – and it is executed first. In the simplest sense, all other parts of your program are launched from the main section either directly or indirectly. Things get a little more complicated than that once you start to write more complex programs but for now you can think of the main section as the ‘main loop’ where things begin to happen in your program code.

[crayon-67634a4bdf0fc687919773/]

After that you should write your lines of program code into this procedure, between the { and } brackets. If you are a beginner, “Hello World” examples are good to understand how the basic feature of a particular programming language works. It is also a good way to understand how to edit text, how the syntax (the rules) of the language work, how to compile and link, how to debug and execute, and how to deploy or release. This full example below is a “Hello World” C++ example that can be run with C++ Builder too.

[crayon-67634a4bdf0fd213584502/]

In C and C++, after every command you use you should put a semicolon “;”. In this example above we print a text with std::cout method and then we wait to get a character input (key press) with getchar(); functions, then we exit and return 0; which means our main app has run successfully and exits.

In this example above we define main() function as a integer (int) function, that means we should return a integer value. Here, we print a text with printf() function and then we wait to get a character input (key press) with getchar(); function, sometimes this is necessary to see results when running it. Then we exit and return 0; which means our main app successfully ran and exited.

You can write these C++ codes above into Dev-C++ code editor or you can copy and paste it. If you are a beginner, we highly recommend you to write codes. This will help you to understand how C++ works and you can see your first mistakes when you are coding.

3. After this step, you can compile by pressing F9 run your code by pressing F10, or you can use Compile and Run buttons in Dev-C++ editor. This will write the “Hello LearnCPlusPlus”. Dev-C++ supports C language too, you can compile the C example below with Dev-C++.

[crayon-67634a4bdf0fe792582699/]

How to compile and run a C++ program for free with C++ Builder CE?

You can edit and run C or C++ code using C++ Builder. C++ Builder is a modern powerful C++ IDE. It has C and C++ compilers allowing you to carry out any variety of professional quality development. C++ Builder has a free C++ Builder Community Edition. There is also a paid C++ Builder Professional / Architect / Enterprise version too.

1. Download the free C++ Builder Community Edition and install it.
2. In C++ Builder, create a new console application from the File->New->Console Application – C++ Builder menu . Chose C++ Language as a Source Type and Target Framework as None from the next window and press OK. ,

The RAD Studio C++ Builder Welcome Screen

You can use same “Hello World” C++ example as below,

[crayon-67634a4bdf0ff821379066/]

You can write the C++ code shown above into the C++ Builder code editor or you can copy and paste it. If you are a beginner, we highly recommend you to write the code yourself. This will help you to understand how C++ works and you can see your first mistakes when you are coding.

How to compile and run a C++ program with a C++ IDE?

In C++ Builder you can simply press Run Button (without debugging or with debugging) or F9 key to compile and run your code, or you can use Run Menu to compile and run too.

How to compile and run a professional C++ program with a C++ IDE?

Although the free C++ Builder Community Edition is extremely powerful it is intended for students, beginners, and startups. If you are a regular business or do not qualify for the free community edition then you can download a free trial of the very latest full RAD Studio C++ Builder version.

C++ Builder is the easiest and fastest C and C++ IDE for building everything from simple to professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Download RAD Studio 11 Now

See What’s New in RAD Studio 11

Exit mobile version