<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.compsci.ca/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.compsci.ca/index.php?action=history&amp;feed=atom&amp;title=Window_closes_instantly</id>
		<title>Window closes instantly - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.compsci.ca/index.php?action=history&amp;feed=atom&amp;title=Window_closes_instantly"/>
		<link rel="alternate" type="text/html" href="http://wiki.compsci.ca/index.php?title=Window_closes_instantly&amp;action=history"/>
		<updated>2026-04-10T02:02:25Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.16.0</generator>

	<entry>
		<id>http://wiki.compsci.ca/index.php?title=Window_closes_instantly&amp;diff=3571&amp;oldid=prev</id>
		<title>Wtd at 00:28, 18 October 2008</title>
		<link rel="alternate" type="text/html" href="http://wiki.compsci.ca/index.php?title=Window_closes_instantly&amp;diff=3571&amp;oldid=prev"/>
				<updated>2008-10-18T00:28:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;It's quite common for new programmers to run into the confusing situation where their program compiles, but then when run, the console window in which the output appears closes instantly.&lt;br /&gt;
&lt;br /&gt;
Let's look at an example of a program where this might be seen.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Hello, world!&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the program is run, a console window very very briefly appears with the output, but then closes.  On modern PCs with very fast processors, this may appear to happen instantly.&lt;br /&gt;
&lt;br /&gt;
The problem is that the console window only exists for the sake of the program.  As soon as the program has completed, it is closed.  For very short, simple programs, this happens very quickly.  &lt;br /&gt;
&lt;br /&gt;
There are two solutions:&lt;br /&gt;
&lt;br /&gt;
* Open a command prompt window and execute the program from there.  The window now has another reason to exist, and when the program finishes, it remains open, awaiting your next command.&lt;br /&gt;
* This is the poorer choice, and only masks the problem.  Add code to your program that prompts the user for input.  The program will not complete until the user actually does input ''something'', meaning that in the meantime the console window remains open.&lt;/div&gt;</summary>
		<author><name>Wtd</name></author>	</entry>

	</feed>