Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++IDERAD Studio

How To Start With A Simple C++ Program

How To Write A Program In C++ For Beginners IDE labeled

The C++ programming language is one of the most powerful programming languages as well as one of the world’s most popular. C++ Builder is a fast and reliable IDE and compiler which is one of the best IDEs you can get in C++ programming for iOS, Windows, and Android. Using a fast and reliable C or C++ compiler is very important for beginners and professionals when learning to write either console apps or C++ GUI apps.

The C++ programming language includes a substantial number of elements of the C language and builds on those solid foundations with object-oriented programming features like Classes, Objects, and Methods. C++ is popular, and often appears in at least top 3 rankings for computer languages but if we consider its other variations and its usage on programmable microchips and IoTs it is actually the number 1 most used programming language. C and C++ compilers are great tools to develop when they are paired with a professional C++ IDE such as RAD Studio and C++ Builder.

Learn about the main features of the open source text editor and IDE for C++ on Windows 11 in this article.

How to run a simple C++ program with C++ Builder ?

To run a simple C++ program you need an editor with which to write your code and a compiler to turn that code into an executable program. The best and the simplest way is to use a C++ IDE which includes a compiler as part of its toolset. The C++ Builder CE version is free C++ IDE for students, beginners, and startups. It enables the building of applications on the Windows, 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. C++ Builder comes with RAD Studio – the RAD stands for Rapid Application Development, a name it definitely deserves. C++ Builder comes from a venerable history which began with the incredibly popular Borland TurboC in 1990. This was later renamed Borland C++ Builder. Now, under the Embarcadero brand, it comes with new versions, features, updates, and support. C++ Builder comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey FMX framework for cross-platform UIs.

Switch to a better built tool box like a professional C++ compiler and develop small applications for different platforms for free.

You can download the free C++ Builder Community Edition here: https://www.embarcadero.com/products/cbuilder/starter.
Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder. Please visit https://www.embarcadero.com/products/cbuilder.

A simple C++ program as a GUI application with C++ Builder

If you download C++ Builder Community Edition (or RAD Studio CE version) or any Professional, Architect, Enterprise versions of C++ Builder. Install it on your windows computer and run RAD Studio or C++ Builder. Beginners and students normally start to learn C++ with simple code. Let’s create a new Multi-Device (Cross-Platform) C++ application by using FireMonkey (FMX) framework.

Choose File->New-> “Multi-Device Application – C++ Builder” menu.

How To Start A C++ Program - selecting multi device application from the menu

This will create a New C++ Project for Windows and can be easily compiled for other operating systems like iOS , Android. This will allow you develop C++ apps with FMX UI elements. If you don’t need UI Elements, this means you don’t need VCL or FMX frameworks, you create a console application too. Modern applications have rich GUIs and skinned ‘Styles’. Note that VCL projects are Windows only. FireMonkey FMX projects are multi device (multi-platform) applications that you can compile on Windows to create apps which run on Windows, MacOS, iOS and Android .

When you have created the application select Save all from the file menu to save the new project files to a folder of your own choosing.

How to design your first GUI for a simple C++ program?

Simply drag and drop components from the Palette window on the right side; Memo (TMemo) and Button (TButton) to your form design. Arrange their width, height and position. You can edit each of their properties from the Object Inspector on the left side.

How To Start With A Simple C++ Program - the C++ IDE showing a form with a button on it

Note that you can switch between the GUI Design mode to Code Mode by pressing F12, or vice versa. If you want, you can switch to your header file (.h) of your cpp file (.cpp) from the button tabs. You can change your Build Configuration from the left Project window by setting it to Debug or Release mode. Debug mode allows you to test your program’s operation from inside the IDE. If you select “release mode” the additional debugging code is not included. When you want to create a version of your app which will be used by regular users you should select “release mode” as it applies several optimizations to remove unnecessary code sections and uses the release versions of libraries and components which results in the smallest, fastest possible executable application.

How to add your C++ code to a simple C++ program ?

Double click to Button1 to create OnClick() event for this button. Add these lines into Button1Click() event,

This example above is a modern “Hello World” example for Windows which runs with C++ Builder.

How to compile a simple C++ program ?

Now you can compile this C++ code; just press the F9 key or just click the Run button in the center of top bar. This will let the IDE check your code and compile both the Unit and project files and link them together. You can also use the Run menu from the top to run your application.You should see this below as a form application

How To Start With A Simple C++ Program- a hello world C++ program shown in the IDE

If you get an error, check your code – it’s easy to mistype or have the braces (“}” characters) in the wrong place. Note that C++ is case sensitive, so upper and lower characters should be also same. Then press the F9 key or just click the Run button again.

From this point, you can add more codes or you can switch back to design mode by pressing F12. And you can add more components, then more codes. This is how modern C++ coding works with an UI Toolkit. You can try this simple “Hello World” example below too,

Is there a simple C++ program example as a console application?

You can develop console apps in C++ Builder too. This full example below is a “Hello World” C++ example that can be run with C++ Builder.

Let’s explain this small example above. When you start coding in C or C++, first of all, you should include libraries that you use. Generally for beginners iostream library is enough to print outputs and get inputs in simple beginner apps. We can include this library as below,

Next, you should add the main procedure (the main program, the main function) as below,

After that you should write your programming code lines into this procedure, between { and } brackets. If you are a beginner “Hello World” examples are good to understand feature of that programming language. It is good to understand how to edit text, how to write in its format, how to compile and link, how to debug and execute, how to deploy or release.

In C++, after every command you use you should put ; to the end of your commands. In this example above we print a text with cout method of std library. We use :: operator as a library dependency, for example std::cout, and we use << for the output. Here is a example to print a text as an output,

In this example main() function is a integer (int) function, that means we should return an integer value. Thus, we should return 0 by using return 0; which means our main app successfully run and exit.

How to compile a simple C++ program in Command Prompt

If you don’t want to use project settings and you just want to compile a *.cpp file you can use compilers listed in bin directory of C++ Builder or RAD Studio. For example for an 32bit Windows application you can use C++ Builder Compiler for Windows 32bit bcc32.exe as below,

or you can use bcc32c C++ Builder CLANG Compiler for Windows 32bit as below,

Note that when you compile a C file in this way, compiler will generate all exe and other output files to the same folder.

Don’t forget, you can also use Borland C++ Compiler and Dev-C++ to compile C programs. We highly recommend you use C++ Builder CE version that may allow you switch easily to the Professional version of RAD Studio.

How to compile a simple C++ program in Linux?

You can use same C++ example code above in Linux. Write that example code in an editor (i.e Sublime Text Editor) and save as “myapp.cpp”. After these steps, in Terminal, go to folder of your C++ file and type g++ and your file name. Be sure that you are supervisor or allowed to save files to that folder. For example, you can compile your app as shown below.

In Linux, GNU C/C++ comes as default language installed. Generally gcc compiler is used as a C compiler and g++ compiler is used as C++ compiler. If your c++ program file is myapp.cpp you can compile this with g++ command as below,

Be sure that you have permission to write to folder there. Now you can easily run your myapp.out as given below,

Here is the full input and output process in Linux terminal

How to develop a simple C++ program with RAD Studio?

Here are the features of the C++ Builder 11 version;

  • Provision apps for Windows 11
  • Compile for Android API 30
  • Compile for M-series (Apple Silicon) processors
  • Design on high-DPI 4k+ screens
  • View VCL Styles in design time
  • New & modernized VCL components  
  • Use enhanced remote desktop support to collaborate remotely 

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. In the preceding sections we’ve shown you how easy it is to create a very simple C++ app. Obviously, a genuinely useful C++ application has far more complexity to it and contains all sorts of things like styles to make your app’s screens look gorgeous and professional on any target device, along with powerful features like REST server connectivity and retrieving and manipulating data from databases and so on. You can read more about some of these features over on LearnCPlusPlus.org as well as in our C++ articles here on this blog.

Also, you’ll find the answers to several questions about String Operations in C++ software.

See What’s New in C++ Builder 11

Download C++ Builder 11 Now

cbuilder_11_512x5121x-6842885

C++ Builder is the easiest and fastest C and C++ IDE for building simple or 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.

For students, beginners, and startups you can download a free C++ Builder Community Edition. If you are a professional developer, you can download a free trial copy of Professional, Architect, or Enterprise versions of C++ Builder.


What's Coming in Delphi, C++Builder, and RAD Studio 11.2 Alexandria

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and other operating systems. He was born in 1974, Eskisehir-Turkey. He graduated from the Department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later, he started to work in the same university as an assistant. He received his MSc and Ph.D. degrees from the same department of the same university. Since 2012, he is the founder and CEO of Esenja LLC Company. Some of his interests are Programming, Thermodynamics, Fluid Mechanics, and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations. He has married, and he is a father of a son.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES