C++C++11C++14C++17Introduction to C++Learn C++

How To Run C++ Program in Terminal

How To Run C++ Program in Terminal

The C++ programming language is great – it’s very popular and extremely powerful for all sorts of programming. It one of the most popular programming languages and often features among the two three languages on any lists. Perhaps 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++ Editor and compiler, and we teach how you can start coding with simple examples as a first step.

How to create a C++ program to run in terminal

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.

Then, you can follow these steps to run your program,

  1. Create a new Project (a console application, a solution)
  2. Start coding with very simple code and save all project files including cpp files.
  3. Press Run Button or Keys of IDE or use a compiler to compile your code.

As an example, now, let’s do these steps in C++ Builder.

  1. Use menu File ->New->”Console Application – C++ Builder” to create a new C++ console application. In the next window, press OK to write your code.

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,

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.

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,

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 pause system with system("pause"); then we exit and return 0; which means our main app has run successfully and exits.

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

How to run C++ program in terminal with the RAD Studio Command Prompt?

If you create and save your C++ Builder C development project as described above, you can run RAD Studio Command Prompt.

1. First be sure that RAD Studio or C++ Builder is installed and the project and C files of this project is saved in a folder.
2. Press Windows Key and write “RAD” then in Windows Menu choose” RAD Studio Command Prompt”. This will execute Command Prompt with RAD Studio settings.
3. Use CD command to navigate to your project folder. For example,

2. coding is done now you can save all your project files to a folder. Use File->Save Project As to save all your files.

3. After this step, you can compile and run by pressing F9, or you can run your code by pressing F10, or you can use Compile and Run buttons editor. This will print out the “Hello LearnCPlusPlus”. C++ compilers support C language too

4. type dir command to see your C project files
5. *.cbproj file is your project file. Use msbuild to use MS Build app. This will build your application with project settings; it will use appropriate C++ compiler and linker defined in this project file. For example,

6. This will compile and list you errors and warnings as given example below,

How To Run C++ Program in Terminal the RAD Studio command prompt

7. The executable file is generated in an output folder. This folder can be Win32, Win64, iOS, Android etc. You can check these folders by cd and dir commands. And also project can be in Debug or Release folders, depends on your project. Our project was 32bit Windows Console Application (Win32) and it was in Debug mode (Win32\Debug folder). So we can navigate to Win32 and Debug folder as below,

If you type dir command you will see all output files in Debug folder as in example below,

8. Now you can execute the executable *.exe file

How to run C++ program file in terminal or command line with RAD Studio command prompt and compiler?

If you don’t want to use project settings and you just want to compile a *.c 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, the 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 to the professional version easily.

How to run C++ program without compiling in terminal

How To Run C++ Program in Terminal the C++ Builder logo

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.

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.

How To Run C++ Program in Terminal the RAD Studio IDE

C++ Builder IDE has mainly 5 Parts, the Code Editor Window and Form Designer, Projects Window, Palette Window, Structure Window, Object Inspector Window. You can find more , less commonly used windows from the main IDE menu as well as the right-click context menus. All the basic sections can be summarized in this IDE picture above.

How to build a C++ program in Linux with the g++ compiler?

How To Run C++ Program in Terminal the C++ Linux marriage is made in heaven

On Linux, GNU C/C++ comes as the default programming language already installed. If you are using WSL on Windows, then you can use the following command in the WSL terminal to install GCC:

Generally, the gcc compiler is used as a C compiler and g++ compiler is used as a C++ compiler. If your c program file is myapp.c you can compile this with the gcc 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,

How to build and run a C++ program in Linux terminal?

f you are using an actual Linux machine rather than a Windows machine, then you can use any text editor to create C++ files. Sublime Text Editor is a light editor for beginners. If you want only to edit in console Vim editor is good. Eclipse CDT is a modern C++ editor for Linux. Spyder is a good editor for Python and C++. There are other C++ editors which can be used in different Linux distributions. Some of these are, VS Code for Linux, and CodeBlocks for Linux. Let’s write our C++ code as below,

Here is the full input and output process in Linux terminal

How To Run C++ Program in Terminal C++ Logo

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.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++17Language FeatureLearn C++

How To Use Skia Images in C++ Builder?

C++C++17Code SnippetGame DevelopmentLanguage FeatureLearn C++

What Is Skia In Modern C++?

C++C++17Learn C++

How To Use Skia in C++ Builder 12?

C++C++17C++20Introduction to C++Language FeatureLearn C++Syntax

Learn How To Use Clamp (std::clamp) In Modern C++ 17 and Beyond