[C++] 2-1.1 c++ program files and coding standards

[C++] 2-1.1 c++ header files and source files

1. Background

Operating system: IDE
used by windows10 : visual studio comunity 2017
Compiler standard: ISO C++17 standard (std:c++17)
Insert picture description here

2. Program files

Program files, also called code files, include header files and source files.
The suffix of the file is not necessary. It is customary to use the suffix to indicate what type of file it is, which can enhance readability.

The general form of the header file is as follows:
jn10010537.h
jn10010537.hpp
jn10010537.hxx

The usual form of the source file is as follows:
jn10010537.cpp
jn10010537.cxx
jn10010537.cc

Under windows10,
the suffix of the C++ header file we usually see is ".h"; the suffix of the C++ source file is ".cpp";

3. Coding Standards

As long as the program file complies with the grammar of the C++ language, it can be compiled and run theoretically;
however, the program is for people after all, and people need to communicate with each other. Therefore, the logic of the code you write is not necessarily the case for others. I know, if others don’t know, they will not only scold you, but also delete your code...

Coding standards, I compare it to a moral-like constraint, which makes the program more readable.

Examples of coding standards: In
c++ programs, special characters such as "tabs" and "page breaks" are not allowed. Replace "tabs" with 4 spaces in the IDE; and the function must always list the return value clearly For example, in the main main function, write "return 0;" into the code!

4. Coding example

# include<iostream>  //引入标准库头文件;
using std::cout; //避免使用using namespace std;这种习惯可能造成名字空间冲突;

int main() {
    
    
	cout << "hello jn10010537!" << std::endl;
	return 0;	
}

Insert picture description here
Note:
<< is originally a left shift operator. In the above coding example, it is a stream output operator (or stream insertion operator). In this case, it is called operator overloading!
Currently there is no operator overloading feature in java and python.

Guess you like

Origin blog.csdn.net/jn10010537/article/details/115265642