Difference between revisions of "CPP/Debugging/Assert"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==Assert.cpp== <source lang="cpp"> #include <iostream> #include <assert.h> int main() { int i = 2; assert(i == 2); return 0; } </source>') |
Daviddoria (Talk | contribs) (Undo revision 699 by 188.143.232.65 (Talk)) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 3: | Line 3: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
#include <iostream> | #include <iostream> | ||
− | #include < | + | #include <cassert> |
+ | #include <string> | ||
+ | #include <cmath> | ||
− | + | using namespace std; | |
− | { | + | |
− | + | float Sqrt(float n){ | |
− | + | assert(n >= 0); | |
− | + | return sqrt(n); | |
− | + | } | |
+ | int main(){ | ||
+ | |||
+ | Sqrt(16); //pass | ||
+ | Sqrt(-16); //fail | ||
+ | |||
return 0; | return 0; | ||
} | } | ||
</source> | </source> |
Latest revision as of 09:23, 11 February 2011
Assert.cpp
#include <iostream> #include <cassert> #include <string> #include <cmath> using namespace std; float Sqrt(float n){ assert(n >= 0); return sqrt(n); } int main(){ Sqrt(16); //pass Sqrt(-16); //fail return 0; }