c++ - How to print additional information when assert fails? -


often wants to print an additional information, if someone emphasize fails to do so One way to do this is:

  emphasize (vec.size ()> gt; i !! (Std :: cerr & lt; & lt; "wrong:" & lt; ; Vec  

In this way the actual size is printed when stresses fails. But it's ugly, and ! It is also easy to forget, which will correct the claim situation and the program will only continue.

What is the use of people instead of printing additional information on the indictment failure, like the above?

< Pre> defined as # eserate (status) {if (! (Condition)} {std :: cerr & lt; "eserate fail:"

Usage:

  Acer (vec.size ()> 1);  

Result:

  Acer Fail: vec.size () & gt; 1 @ main.cpp (17)  

You can optionally debugbrake () or exit (-1) or your needs Can be placed in the macro on the basis of.

The macro has been updated with different left and right sides:

  define #SSERT (left, operator, right) {if (((! Left) operator (right))} {std:: ser + l; & Lt; "Eserate failed:" & lt; & Lt; #left & lt; & Lt; #operator & lt; & Lt; #right & lt; & Lt; "@" & Lt; & Lt; __FILE__ & lt; & Lt; "(" & Lt; <__LINE__ <<"lt;"). " & Lt; & Lt; #left & lt; & Lt; "=" & Lt; & Lt; (Left) & lt; & Lt; ";" & Lt; & Lt; #right & lt; & Lt; "=" & Lt; & Lt; (Right) & lt; & Lt; Std :: endl; }}  

Usage:

  esrete (A,>, b);  

Result:

  Acer Fail: One & gt; B @ assert2.cpp (8). One = 3; B = 4  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -