Min menu

Pages

VB

Learn c++ plus language

C++ Language OverviewC++

Am I ready to learn a languageC++?

If you are a programming beginner, you should study algorithms before you start studying a languageC++, because you need to know programming principles before you learn any programming language.
Don't worry if you haven't already learned it because we explained the algorithms from scratch. You can learn it here


advice

Don't try to learn a languageC++Unless you learn algorithms before, because you may have great difficulty understanding the code sometimes, even if the code is explained in detail and easy to understand.
Study all the lessons in the same order they are placed because we have explained all the ideas coherently.

what is the languageC++?

C++C Plus Plus is written in Arabic, which is an assembly programming language(Compiled)and Objective(Object Oriented)It includes many features of high-level programming languages(High Level)and low level(Low Level)This means that you are able to do whatever you want with it.
This wonderful language is designed to work on all well-known operating systems such as Windows, Mac, Linux, Android etc.. It is considered one of the most powerful and most popular programming languages ​​ever and it is called"mother of languages"Because it is a powerful language and has been around for a long time.

This language was built primarily as a language developmentCFrom beforeBjarne StroustrupWhile working in laboratoriesBellTo be his dissertation in a doctoral dissertation in general1979 .
From then until the present time, this language has been continuously developed, and its latest official version isC++ 17.

There is no official logo for the languageC++But usually, when you search for courses to learn online, you will find them using a logo that looks like the following.

What can I develop in a languageC++?

languageC++It is considered a general target language(General Purpose)Which means it is able to build any program.
Its real strength is manifested in large projects and programs such as:

  • Building and developing operating systems and among the most famous operating systems built in this languageWindows, Linux, MacOS, Android.

  • Building and developing large programs such as Adobe programs( Such asPhotoshopAnd thePremier) and the browserFirefox.

  • Building and developing games and one of the most famous games developed in this languageCounter Strike, MacOSDoom, Warcraft.

Language FeaturesC++For developers

  1. It is very popular and there are many references for those who want to learn it.

  2. The ability to control the use of memory significantly.

  3. It is light, fast and consumes less system resources compared to languages ​​such as Java and Python.

  4. It is possible to convert code written in a languageCfor code in languageC++Easily.

Language FeaturesC++About other programming languages

  1. Open source
    will not pay any money to work on a languageC++It is open source and free and will remain free for life.


  2. Lightweight
    that you can program with even if your computer is weak or old.


  3. Simplicity
    is very easy to learn after you understand object programming.


  4. Translation speed
    The language is translatedC++into commands that the device understands very quickly.


  5. object language(Object Oriented)
    with that languageC++It is designed to be close to the hardware of the device and close to low-level languages, but it allows its user to build classes and deal with them using object-oriented programming methodologies.(OOP)Such as inheritance, polymorphism and other principles that you will learn later in the course.


  6. Multiple models
    allow languageC++For its user to choose the appropriate method for him to write the code from among several different models such as the structural model(Structural)similar toCAnd the object model(Object Oriented)Similar to Java.


  7. Great
    language supportC++It is a relatively old and widely spread language, which made it a very popular language, various and multiple learning resources, and great support from the developer community.

Who is this reference prepared for?

This reference is intended for all people who want to learn.
So whether you are a hobbyist, student or programmer, this reference will help you understand the basics of a languageC++And reach a very advanced level.

In the next lesson we will guide you to download the tools that we will use to build and run codeC++on your computer.

C++ Download and Install ToolsC++

How to make a program written in a languageC++

The code that you write on the computer does not work directly, but goes through several stages in succession until it works exactly as in the following image.

So the code written in a language passes throughC++in three stages until it finally becomes a program that can be run on the computer.
In the beginning doesthepreprocessorTrimming and preparing text files to enter the assembly process(Compiling)Where text files are converted to files(typeBinary)The computer understands it while preserving some characteristics of the code, such as the names of variables and functions(Linker)Connecting all the different parts of the program and merging them together to become one executable file(typeEXE)It can be launched at any time like any normal application.


Technical information

thepreprocessor, theCompilerAnd thetheLinkerThey are just small programs that work together to convert all the code we wrote in the project to a regular program that can be run in one click.

Preparing the work environment for developing applications in a languageC++

There are many work environments that enable you to work on software development in a languageC++Whatever operating system you are using such as:
Eclipse- CodeBlocks- CLion- Dev C++etc..

In this course we will teach you how to download, install and use a CodeBlocksfree program to write and test code on your PC.
We will also teach you how to use the online service if you want to write a codeC++Without installing any software on your computer.


note

If you are using a Windows system and you are using a program, Visual Studioyou can use the same to write the code instead of a programCodeBlocks.
To learn how to write codeC++Using the program, Visual Studiosearch YouTube for: visual studio setup for c++and watch any video you want.

If you are using a Mac and use a program, XCodeyou can use the same to write the code instead of a programCodeBlocks.
To learn how to write codeC++Using the program, XCodesearch YouTube for: xcode setup for c++and watch any video you want.


Steps to download, install and open the programCodeBlocks

Watch the following steps to learn how to download and install a software versionCodeBlocksappropriate for your computer.
Note: The reason we use the programCodeBlocksIt is free, easy to use and helps a lot in writing the code.

See the steps »



Steps to create a new project and run it in a programCodeBlocks

Here we have put the steps for creating a new project (any program) inCodeBlocks.
Attention: you have to follow these steps every time you want to try the code on your computer.

See the steps »



Steps to determine the version of the translator(Compiler)

Here we have put the steps for determining the version of the translator and this command will help you choose the version you want easily.
We will also determine which version we will be working on so you need to follow these steps now and follow them whenever you want to change the version of the translator.

See the steps »

The general form of any program written in a languageC++

The main file in the project should look like this.

#include <iostream>

	  int main()
	  {
	  // Here you must put the commands that will be executed when the program is running
	  return 0;
	  }
	

  • The code that executes directly when the program is running is the code we write inside the main () function and before the commandreturn 0 .

  • We'll go into more detail in the next lesson.

line utilityusing namespace std;

When you create any new project, you notice in the file main.cppthat the command is located using namespace std;on the third line as follows.

#include <iostream>

	  using namespace std;

	  int main()
	  {
	  cout << "Hello world!" << endl; // we use it to print any text we want for the user but don't worry about it now cout << command
	  return 0;
	  }
	


Why do I find the command using namespace std;in the project code if it is not mandatory?

In the beginning this line means that you want to include the things inside the library stddirectly in the project.
If you want to remove this line, you will be forced to specify the name of the library from which you use the command coutand cinother commands that we will learn in later lessons.

Now the code will look like this in case you want to remove the command using namespace std;from it.

#include <iostream>

	  int main()
	  {
	  std::cout << "Hello world!" << endl; // Where is this C++ command so we specify to the cout compiler before the word std:: note that we added
	  return 0;
	  }
	


In this course, we will include the library stdin most of the examples so that the code size is smaller and easier for you to read, i.e. we will keep it using namespace std;in the code.


note

From now until the end of the series of lessonsC++Your lessons will be small explanations of each new concept you learn, and in this way you will understand all its principles.

C++ Steps to download and install a programCodeBlocks

Steps to download a programCodeBlocks

  1. Search Google forcodeblocks.

  2. Click on the link of the first site that appears in the search results, and the site will be a sitecodeblocksSame as shown in the link.

  1. After opening the sitecodeblocksOfficial, click onDownloadsUntil you go to the page where you can choose the version of the program that you will use.

  1. On this new page you will find several options to download the program.
    Click onDownload the binary releaseBecause it is the easiest version in terms of installation on the computer.

  1. On this page you will find several download options. Scroll down the page until you find the download section for the operating system you are using.
    Note: We're using Windows, so we'll go to the Windows download options.

  2. Then download the programmingw-step.exeBy clicking on the download link that appears next to it from the siteFossHUBor from a websiteSourceforge.net.
    After you click on the download link from the siteFossHUBA new page will open and the program will start downloading automatically.

Here, you have downloaded the programCodeBlocksSuccessfully, your next step is to install it.

Software installation stepsCodeBlocks

  1. after downloadCodeBlocksOpen it to start installing it.
    Right-click on the file, then chooseRun as administrator.

  1. Click onNext.

  1. CheckmarkI agree.

  1. Keep everything selected and pressNext.

  1. Click onInstall.

  1. After the program has finished installing successfully, it will ask you if you want to run it now.
    Click onYesBecause there are simple steps that you must do the first time you run a programCodeBlocksAnd we will do it now.

  1. tap onGNU GCC Compiler,Then click onSet as default,Then click onOK.

  1. Now you will notice that the program interfaceCodeBlocksIt will open and a message will appear to you with four options.
    ChooseYes, associate Code::Blocks with C/C++ file typesThen pressOK.

Here, you have installed the programCodeBlockssuccessfully.

Steps to run a programCodeBlocks

To run the program, you will find its icon on the desktop, and if you do not find its icon, simply search for it, that is, click on the search button and then typecodeblocksAs follows.

After you find the program icon, just click on it and it will open as follows.


Now, come back to the lesson to learn how to create a new project (any program) withCodeBlocksAnd you run it.

C++ Steps to create a new project in a programCodeBlocks

Steps to create a new project

  1. tap onFile,thenNew,thenProjectAs follows.

  1. tap onConsole ApplicationThen the buttonGoAs follows.

  1. Check the optionSkip this page next timeThen click onNextSo that you do not see this page again as follows.

  1. tap onC .++And then click onNextAs follows.


  1. Specify the name you want to put the project and the folder path where you want it to be saved on your computer, then clickNextAs follows.


  1. Do not modify anything on this page, clickNextJust as follows.


  1. After the project is successfully created, it will appear in the list of projects as follows.


  1. To see the main file in the project in which you can write the code, open the folder Sourcesand then click on the file main.cppas follows.


  1. To run this program, which will only show you a sentence "Hello world!", click on the button Build and runas follows.


  1. After running the program, a command prompt will open(which is calledCMDorConsole)It shows the result of the operation as follows.

Steps to run the project correctly

Before running any project, you must convert the project code to an executable file of its type EXE, and here if the code has any problem, you will appear.
When you convert all the project code into an executable file, EXEyou are doing what is calledBuildfor the project.
Note: You can do this with just one click and you will learn how to do it easily shortly.

In a programCodeBlocksYou can convert the project code to an implementation file and run it with just one click if you want and this command is calledBuild and Run.


Take good care

If you modify the project code and just save it without doing itBuild- That is, without converting the project code to an executable file - and then you run it, it will show you when you run the result of the last time you did itBuildAnd not the result of the code you saved last time.

So we always advise you to do soBuildIn case you just want to check the project code.
And we advise you to doBuild and RunAll at once in case you want to check the project code and run it.

C++ Steps to determine the version of the compiler in a programCodeBlocks

If you want to work with code for a specific compiler version, or you want to experiment with things related to a specific compiler version, you must specify the version of the compiler that you want to interpret your code for the computer so that you don't get errors when trying to run the code.

As a simple example, if you want to use the word autoin the code, you must specify a programCodeBlocksYou are dealing with the version of the compiler [-std=c++11]because in older versions of this version the word has not yet autobeen added, which means that it is considered something unknown for the old versions and leads to problems in the code when running it.


Now to determine the version number you are dealing with, you can follow these simple steps:

You are now in the last article