In addition, standardized and easy-to-understand code can be used repeatedly. Standardized Code has a longer life, better maintainability, and more convenient for later extension. It is not important to adopt the indent style, in fact, it is far from important to use specific C ++ code styles in a consistent manner.
One or more debugging tags are defined in the pre-processing C ++ language. 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. The commonly used debugging mark is DEBUG, and the statement sequence is as follows:
- #define DEBUG
-
- #ifdef DEBUG
2. Enable and disable the debugging mark 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 code:
- # 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 {}
-
- }
-
- }
3. Convert variables and expressions into strings, but use string operators to implement conversion output definition.
4. assert () in C ++ ()
In <assert>, 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< 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.
-
- }
- Several important elements of C ++ programming tools
- In-depth analysis of various problems with C ++ development tools
- On the programming skills and skills of C ++ Programming
- Analysis of C ++ programming learning and Experimental System
- Common methods and skills for C ++ Programming