Site icon Learn C++

How To Start Programming In C++

How To Start Programming In C++

I think you heard, the C++ programming language is one of the most popular programming languages and often features among the top two or three languages on any lists. Now you want to start programming in C++ but don’t know where to start? In this post, we explain simply how you can download a free C++ IDE and compiler after which we show you how to start coding using some hello world C++ examples as a first step.

How to start learning programming in C++

If you want to develop a windows application the easiest way is to use a C++ IDE and Compiler that you can use to edit and compile your code into an executable windows application – the actual program that your users will run.

C++ is a powerful programming language with many features that enable you to write almost any app you could ever want. Using a fast and reliable C++ Compiler and IDE is very important for beginners and professionals to develop C++ apps for Windows and other operating systems. When a user wants to develop modern C++ applications, they should learn to use a professional IDE.

An C++ IDE or integrated development environment (IDE) is a software application that provides a complete set of features and tools for application development. Code is generally written in text format – you could easily edit or modify your code using text editors like Notepad, Word, WordPad, UltraEdit or similar, but for a developer, beginner or professional, however, an IDE is really important because it includes lots of helpful features like highlights, auto code completion and a C++ help system. The C++ IDE allows you to run, test, debug, deploy, merge or transform code in one place using an environment which is specially created to work with C++ code and programs. If you wish to target other platforms such as mobiles devices like phones and tablets, or alternative desktop operating systems like macOS or Linux then choosing a C++ IDE which can support all of these in one place is vital.

How to download and start programming in C++ with the free C++ Builder CE

If you are new to C++ and want to compile code for the first time we recommend you try the free C++ Builder Community Edition for students, beginners, and startups. 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. C++ Builder comes with Rapid Application Development Studio, also known as RAD Studio, and C++ Builder is one of the most professional IDE’s that work under RAD Studio. 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. More details about C++ Builder & RAD Studio for the beginners can be found in Official Wiki of Rad Studio.

We have a great selection of free C++ IDE and professional C++ IDE. Tools like C++ Builder CEDev-C++, and even the BCC32 command line compiler. Although C++ Builder’s primary purpose is to be the best available C++ IDE which helps developers be at their most efficient and effective possible selves it is also quite capable of editing and compiling most C code thanks to C and C++ having a shared lineage. The latest version RAD Studio 11.2 is announced with many new features.

C++ Builder CE is the easiest and fastest C & C++ IDE for developing simple or professional applications on different operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files and LSP support. C++ Builder comes with Rapid Application Development Studio, also knowns as RAD Studio, and C++ Builder is one of the most professional IDEs that work under RAD Studio.

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.

How to start programming in C++?

If you download C++ Builder Community Edition (or RAD Studio CE version) or any Professional, Architect, Enterprise versions of C++ Builder, or Dev-C++, VC++, GNU C/C++ then we can start to code,

  1. Create a new Project (a console application, a solution)
  2. Start coding with very simple code, for example with a simple example

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-67418cc7d94f6572907438/]

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-67418cc7d9506553025564/]

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.

Here is Hello World C++ example as a console application,

[crayon-67418cc7d9509341464412/]

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. This will print out the “Hello LearnCPlusPlus”. C++ compilers support C language too, you can compile the C example below,.

Here is Hello World C example as a console application,

[crayon-67418cc7d950b955412501/]

How to start programming in C++ Builder with the FireMonkey FMX framework?

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. Let’s start to develop a C++ app with GUI y using FireMonkey framework.

How to create a new C++ Project?

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.

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 a GUI’s and skinned Styles. Note that VCL projects are Windows only and FireMonkey projects are Multi Device (multi-platform) applications that you can compile and run on Windows, MacOS, iOS and Android .

Save all Unit files and Project file to a folder.

How to design your first screen or form when you start programming in C++?

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.

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.

How to add your C++ code to your first C++ program?

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

[crayon-67418cc7d950d608515528/]

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

How to compile your C++ project?

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

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.

How to start programming in C++ Builder with the VCL framework?

If you succeed in the steps above and want to know how to compile modern and visual application in VCL, you can do same with a VCL application. Note that VCL applications are only for Windows operating system, you cannot compile them for other operating systems (you can use FMX for that). There are slight differences between VCL and FMX components.

Now let’s create a Visual and Modern C++ example in C++ Builder,

  1. Open C++ Builder or RAD Studio IDE
  2. Create a new Windows VCL Application in C++ Builder from File->New menu. This will allow you develop C++ apps with VCL UI elements.
  3. Save all units and project files with “HelloWorld_” prefix in a HelloWorld folder.
  4. Add a Memo (TMemo) and a Button (TButton) from the Palette to your Form. TMemo component is good to display all outputs as in console applications.
  5. Double click the Button to create OnClick() event, inside that Button1Click event write lines as given in the example below,
  6. Run project by hitting F9 or click Run with Debugging
  7. If there is error, please check your lines
  8. If all is fine then save all project
  9. if you check your header file you will see all your objects (Memo, Button etc. ) are automatically defined as below. You don’t need to change anything here

If you are a beginner “Hello World” examples are good to understand features 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, and how to deploy or release the finished program. This example below is a modern “Hello World” example on Windows which runs with C++ Builder.

Now, lets use the most powerful print function in our modern C++ application. You can use talented printf function as a method of string to print Pi number (M_PI) as below,

[crayon-67418cc7d9510399621305/]

You can find more details about printf() function and many other examples in LearnCPlusPlus.org.

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