Four debugging skills in C ++ Programming Language
Source: Internet
Author: User
Four debugging skills in C ++ programming language-general Linux technology-Linux programming and kernel information. The following is a detailed description. 1. debugging mark
Applicable to preprocessing # define to define 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. The commonly used debugging mark is DEBUG, and the statement sequence is as follows:
Enable and disable the debugging flag during the running of the program. 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 using namespace std; bool
Debug = false; int main (int argc, char * argv [])
{For (int I = 0; I
Bool go = true; while (go) {if (debug) {debug code} else {}}}
3. Convert variables and expressions into strings.
However, the string operator is used to define the conversion output.
# Define PR (x) cout <# x "=" <'\ N'
4. C language assert ()
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 <assert> using namsapce std;
Int main () {int I = 100;
Assert (I! = 100 );
// Fails} after debugging, go to # include
Add # define NDEBUG to remove the code generated in red}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.