Skip to content

Introduction to C++

C++ is a powerful and versatile programming language that is used to develop a wide range of applications, from system software to games to web applications. It is an extension of the C programming language and provides additional features such as object-oriented programming, templates, and exception handling.

Some of the IDEs that you can use for C++ programming are:

  1. CodeBlocks with the MinGW compiler.
  2. Visual Studio Code with the C++ extension.
  3. Cxxdroid for Android devices.
  4. cppCode for iOS devices.
  5. OnlineGDB an online IDE for C++. However, I would still recommend installing an IDE on your device so that you can code offline.

Although, I highly recommend programming on a computer rather than a mobile device, as it is easier to code and debug on a computer, and there are some features that are not available on mobile devices.

How to Start Programming in C++

Here’s how you can start programming in C++ with some of the IDEs mentioned above:

CodeBlocks

  1. Open CodeBlocks. You can either find the shortcut on your desktop or search for it in the Start menu.

    A screenshot of CodeBlocks in the Start Menu

  2. Create a new project.

    Click on the File menu and select New > Project....

    A screenshot of the File menu in CodeBlocks

  3. Select the correct template.

    Double click the Console Application Project Template.

    A screenshot of the Codeblocks Project Templates

  4. Select the language type and project details.

    Select C++ as the language and click Go, then set the project title and location. The other fields gets filled automatically, so leave it as is.

    A screenshot of the Project Language Selection

    A screenshot of the Codeblocks Project Title and Location

  5. Select the Compiler.

    Afterwards, set the Compiler as GNU GCC Compiler and click Finish.

    A screenshot of the Compiler Selection

Important Parts of Codeblocks

There are a lot of buttons and menus in CodeBlocks, but here are some of the important ones that you will use often:

  1. Compiler Buttons: There are three buttons that you will often use as you code in C++. From left to right, They are the Build, Run, and Build and Run buttons.

A screenshot of the Compiler Buttons in CodeBlocks

When you click the Build button, CodeBlocks will compile your code and check for any errors. If there are no errors, it should open a Terminal window with the output of your program.

If you click the Run button, CodeBlocks will run the last compiled program.

And if you click the Build and Run button, CodeBlocks will compile your code and run the program afterwards. This is the button that you will often use when you are coding, instead of needing to click the Build button and then the Run button separately.

  1. Management Area: Under the Project Tab in the Management Area, you can see the files that are in your project. Including the main.cpp file, which is the file that you will be coding in, found under the Sources folder.

A screenshot of the Management Area in CodeBlocks

Incase you cannot see the Management Area, you can click on the View menu and select Manager to show it.

A screenshot of the View menu in CodeBlocks with Manager highlighted

  1. Logs Window: In this window there are several kinds of logs. The most important one is the Build log which shows the output of the compiler when you click the Build or the Build and Run button.

A screenshot of the Logs Window in CodeBlocks

If you cannot see the Logs Window, you can click on the View menu and select Logs to show it.

A screenshot of the View menu in CodeBlocks with Logs highlighted

Cxxdroid

  1. Open Cxxdroid.

    You can either find the shortcut on your home screen, search for it in the app drawer or open it in the Play Store.

    A screenshot of Cxxdroid in the Play Store

  2. You’re good to go, you can start coding in C++ right away.

    A screenshot of Cxxdroid

  3. To run your code, you can click the Run button at the bottom-right corner of the screen.

    A screenshot of the Run button in Cxxdroid

Main Structure of a C++ Program

Here is the basic structure of a C++ program:

Library Declarations

main.cpp
#include <iostream>
using namespace std;
int main() {
// Your code here
return 0;
}

The number sign or hash # is used to include libraries in C++. The iostream library is used for input and output operations in C++.

Namespace Declaration

main.cpp
#include <iostream>
using namespace std;
int main() {
// Your code here
return 0;
}

The using namespace std; statement tells the compiler to use the std namespace. The std namespace contains the standard C++ library. This means that you can use the functions and objects in the std namespace without having to write std:: before each function or object. For example, you can write cout instead of std::cout.

Main Function

main.cpp
#include <iostream>
using namespace std;
int main() {
// Your code here
return 0;
}

The main() function is the entry point of a C++ program. The program starts executing from the main() function. The int before the main() function indicates that the function returns an integer value. The return 0; statement at the end of the main() function indicates that the program has executed successfully.