Introduction to the

C++ is an intermediate programming language that allows both high-level programming for applications and low-level programming for libraries that work closely with hardware.

The characteristics of

C++ language is the successor of C language, C language is the use of procedural programming, and C++ language on this basis added object-oriented programming, support classes, with inheritance, abstraction, polymorphism and encapsulation characteristics.

standard

Due to years of development, C++ has been widely used, but there are many different versions and different compilers at the same time, which causes problems in portability and interoperability and requires standardization. In 1998, the first C++ standard was approved by the ISO standards committee, ISO/IEC 14882:1998. The widely adopted C++ standard was approved in August 2011, which is ISO/IEC 14882:2011, or C++11.

use

C++ is commonly used to develop operating systems, device drivers, office software, Web servers, databases, cloud-based applications and search engines, and compilers for writing new programming languages.

Executable file

What we call launching an application, in the programming world, we call launching an executable. Generating an executable consists of three steps:

  1. Writing C++ code
  2. The compiler compiles C++ code to generate object files
  3. The linker links the target file to an executable

Note: The process of generating object files ignores the dependence on code in other files. The job of resolving code dependencies is left to the linker.

Write your first C++ program

For our first C++ program, we’ll print a Hello World on the screen, keeping with industry practice. On Ubuntu or MAC we use Vim to create a file called hello. CPP and type the following code

#include <iostream>

int main()
{
    std::cout << "Hello,World!" << std::endl;
    return 0;
}
Copy the code

After entering the code, type the following command on the command line:

g++ -o hello Hello.cpp
Copy the code

G++ -o calls the g++ compiler and linker to generate an executable named hello.