What kind of C ++ code can be regarded as standardized and easy-to-understand? There will be countless arguments in the details. In fact, no matter what the style and habits are, good code has several common features: good naming, consistency, and comments,The following describes the C ++ code.
The debugging tag applies to preprocessing # define defines one or more debugging tags. In the code, use # ifdef and # endif for debugging management. After the program is finally debugged, you only need to use the # undef flag to debug the code. Common debugging labels are DEBUG and C ++ code statement sequences:
- # Include< Assert>
-
- Using namsapce std;
-
- Int main ()
-
- {
-
- IntI=100;
-
- Assert (I! = 100); // Fails
-
- }
-
- After debugging is complete, go to # include<Assert>Add # define NDEBUG to remove the code generated in red.
-
- }
During running, the debug flag is enabled and disabled during running. You can set a debug bool flag. This is more convenient for the program running on the command line.
For example, the following C ++ code:
- #define DEBUG
- #ifdef DEBUG
The macro is in progress. When assert is used, a parameter is provided, that is, a true expression. The Preprocessor generates code to test the assertions. If the assertions are not true, an error message is sent to indicate what the assertions are and if they fail for a while, the program will terminate.
- # Include<Iostream>
-
- # Include<String>
-
- Using namespace std;
-
- BoolDebug=False;
-
- Int main (int argc, char * argv [])
-
- {
-
- For (intI=0; I<Argc; I ++)
-
- If (string (argv [I]) ="-- Debug=On")
-
- Debug=True;
-
- BoolGo=True;
-
- While (go)
-
- {
-
- If (debug)
-
- {
-
- Debug code
-
- } Else {}
-
- }
-
- }
The above tutorials mainly introduce the good C ++ code style, How to Write secure code, and program debugging technology in the Visual C ++ environment, this content is important for new employees to grow from students to Real programmers, gradually participate in the development of actual projects, and read Third-Party code.
- How to better learn the C ++ Language
- Study how to adjust Visual C ++ language by ADO
- Detailed description of Visual C ++ programming Database
- Detailed usage and maintenance of the C ++ Library
- Two classification methods for analyzing the complexity of C ++