C++ tutorial

Next >>


C ++ is an object-oriented programming language. C ++ is the follow-up to C, to which they added classes, virtual functions, templates, exceptions, multiple inheritance, operator overwriting, dynamic allocation, and other new features. It was standardized in 1998.
Programs (also called source codes) are compiled by a compiler. This is also a program that converts source codes into object codes that can be run by the computer.

A C ++ program consists of one or more text files saved with the .cpp extension.

Install the work environment

For all of the following examples, we will work with the Codeblocks program, which is free and offers all the C ++ programming features (edits the source code, compiles, and runs the program).
After downloading and installing the program, its interface shows that in the figure below:


Our first hello program.


After writing the program, we will save it as hello.cpp, then compile it using the Build menu, followed by Compile current file. After compilation will result the hello.o file. If our program also contains the main function, the executable file will result: hello.exe.


To run our program, we use the Build menu, followed by Run.


Following the execution of the program, the result will appear in the console as follows:


Now let's talk about the program.
When program compile begins, preprocessor C is called to handle the preprocessor directives found in the source code. The preprocessor directives start with #. For example, the directive:

# include<iostream.h>

means the inclusion of the header file required for read and write operations.
Then follows the main function, with which the program starts.

int main()

The following instruction is a statement. The statements are executed in order of their appearance. Our statement:

std::cout << "Hello!";

specify that the standard output (std :: cout) will be used, which is usually the computer screen, then the characters << indicates that something will be inserted and then follows the "Hello" text that will be inserted. The statements end with the character;. Next, the instructions:

return 0;

which indicates the end of life of variables of the main () function, means the end of the process.

Code to add 2 numbers:


Creating a directory:


Creating a file:


Deleting a file:


Writing on a text file:


Read the content of a text file:

Next >>

Visit my websites: