<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://devwiki.neosys.com/index.php?action=history&amp;feed=atom&amp;title=Assert_examples</id>
	<title>Assert examples - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://devwiki.neosys.com/index.php?action=history&amp;feed=atom&amp;title=Assert_examples"/>
	<link rel="alternate" type="text/html" href="https://devwiki.neosys.com/index.php?title=Assert_examples&amp;action=history"/>
	<updated>2026-04-07T01:09:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>https://devwiki.neosys.com/index.php?title=Assert_examples&amp;diff=1038&amp;oldid=prev</id>
		<title>AlexNenko: Created page with &#039; // main1.cpp - demonstrates standard usage of asserts  #include &lt;iostream&gt;  #include &lt;cassert&gt;  int main() {     int x = 3;     cout &lt;&lt; &quot;Hello, world !\n&quot;;  &lt;font color=&quot;red&quot;&gt;  …&#039;</title>
		<link rel="alternate" type="text/html" href="https://devwiki.neosys.com/index.php?title=Assert_examples&amp;diff=1038&amp;oldid=prev"/>
		<updated>2010-11-26T15:13:04Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039; // main1.cpp - demonstrates standard usage of asserts  #include &amp;lt;iostream&amp;gt;  #include &amp;lt;cassert&amp;gt;  int main() {     int x = 3;     cout &amp;lt;&amp;lt; &amp;quot;Hello, world !\n&amp;quot;;  &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;  …&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; // main1.cpp - demonstrates standard usage of asserts&lt;br /&gt;
 #include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 #include &amp;lt;cassert&amp;gt;&lt;br /&gt;
 int main() {&lt;br /&gt;
    int x = 3;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Hello, world !\n&amp;quot;;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;   assert( x == 4);&amp;lt;/font&amp;gt;             &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// aborts here with message &amp;quot;Assertion failed: x == 4, file main1.cpp, line 7&amp;lt;/font&amp;gt;&lt;br /&gt;
    return x;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 // main2.cpp - demonstrates how to avoid aborting a program&lt;br /&gt;
 #include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;#include &amp;lt;cassert_warn&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 int main() {&lt;br /&gt;
    int x = 3;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Hello, world !\n&amp;quot;;&lt;br /&gt;
    assert( x == 4);             &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// print &amp;quot;Assertion failed: x == 4, file main.cpp, line 7&amp;lt;/font&amp;gt;&lt;br /&gt;
    return x;                    &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// ... and immediately returns successfully&amp;lt;/font&amp;gt;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 // main3.cpp - demonstrates how to avoid aborting a program&lt;br /&gt;
 #include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;#include &amp;lt;cassert_pause&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 int main() {&lt;br /&gt;
    int x = 3;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Hello, world !\n&amp;quot;;&lt;br /&gt;
    assert( x == 4);             &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// print &amp;quot;Assertion failed: x == 4, file main.cpp, line 7&amp;lt;/font&amp;gt;&lt;br /&gt;
    return x;                    &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// print &amp;quot;Press any key to continue ...&amp;quot; and waits for keypress&amp;lt;/font&amp;gt;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 // main4.cpp - demonstrates how to modify asserts on per statement basis&lt;br /&gt;
 #include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;#include &amp;lt;cassert_exodus&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 int main() {&lt;br /&gt;
    int x = 3;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Hello, world !\n&amp;quot;;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;   assert( x == 4);&amp;lt;/font&amp;gt;             &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// aborts here with message &amp;quot;Assertion failed: x == 4, file main1.cpp, line 7&amp;lt;/font&amp;gt;&lt;br /&gt;
    return x;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 // main5.cpp - demonstrates how to modify asserts on per statement basis&lt;br /&gt;
 #include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;#include &amp;lt;cassert_exodus&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 int main() {&lt;br /&gt;
    int x = 3;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Hello, world !\n&amp;quot;;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;   assert_warn( x == 4);&amp;lt;/font&amp;gt;        &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// print &amp;quot;Assertion failed: x == 4, file main.cpp, line 7&amp;lt;/font&amp;gt;&lt;br /&gt;
    return x;                    &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// ... and immediately returns successfully&amp;lt;/font&amp;gt;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 // main6.cpp - demonstrates how to modify asserts on per statement basis&lt;br /&gt;
 #include &amp;lt;iostream&amp;gt;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;#include &amp;lt;cassert_exodus&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
 int main() {&lt;br /&gt;
    int x = 3;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;Hello, world !\n&amp;quot;;&lt;br /&gt;
 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;   assert_pause( x == 4);&amp;lt;/font&amp;gt;        &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// print &amp;quot;Assertion failed: x == 4, file main.cpp, line 7&amp;lt;/font&amp;gt;&lt;br /&gt;
    return x;                     &amp;lt;font color=&amp;quot;green&amp;quot;&amp;gt;// print &amp;quot;Press any key to continue ...&amp;quot; and waits for keypress&amp;lt;/font&amp;gt;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>AlexNenko</name></author>
	</entry>
</feed>