C++ syntax rules

C++ syntax rules

  • Original rules:

    \1. Each "grammatical unit" (component) is separated by any number (at least 1) separator.

    Separator: space, or tab key, or newline character.

    int main(void)

    int

    main(void)

    All are legal.

    intmain(void)

    Is illegal.

    \2. Must use English input method to input (only Chinese can be used in the "string" enclosed in double quotation marks)

    \3. Use after each code; it means the end of this instruction code.

    \4. #include and other preprocessing instructions, one instruction must occupy a line

  • In any case, as long as the most basic principles are followed, the code is legal and can be compiled and executed.

    After understanding the most basic rules, pursue elegant style code (high force style)

    emphasize again:

    Do not deliberately memorize C++ grammar rules (it doesn’t make sense to memorize)

    When you first learn, you only need to master the most basic grammar rules!

#include usage

  • #include is to include header files. The header files are divided into self-written and system-built ones. The built-in ones are included with #include<>, and the ones written by yourself are included in the form of #include" "

  • #include

    <> means to find the file iostream from the default path of the compiler

    The default path depends on the compiler. The paths of different compilers under different platforms are different.

    This default path already contains all the header files needed by the c standard library.

    Header files using the C++ standard library use this method.

  • #include “mytest.h”

    "" means to find the file mytest.h from the current directory

    If it is not found in the current directory, it will be searched from the default path of the compiler.

    Use user-defined header files to use this method.

  • #include <Windows.h> means to copy (copy) all the contents of the file Windows.h to "here".

  • So in general, put the header file at the top of the file, because when compiling, the compiler will copy all of it to the file

Guess you like

Origin blog.csdn.net/qq_44695317/article/details/112483201