Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please note that the code above was tested on Code::Blocks 12.11 and Visual Studio 2012<br> on Windows 7.</p> <p><strong>For forcing your programme stop or wait, you have several options :</strong></p> <hr> <ul> <li><strong>sleep(unsigned int)</strong></li> </ul> <p>The value has to be a positive integer in millisecond. That means that if you want your programme wait for 2 seconds, enter 2000. </p> <p>Here's an example :</p> <pre><code>#include &lt;iostream&gt; //for using cout #include &lt;stdlib.h&gt; //for using the function sleep using namespace std; //for using cout int main(void) { cout &lt;&lt; "test" &lt;&lt; endl; sleep(5000); //make the programme waiting for 5 seconds cout &lt;&lt; "test" &lt;&lt; endl; sleep(2000); // wait for 2 seconds before closing return 0; } </code></pre> <p>If you wait too long, that probably means the parameter is in seconds. So change it to this:</p> <pre><code>sleep(5); </code></pre> <p>For those who get error message or problem using sleep try to replace it by _sleep or Sleep especially on Code::Bloks.<br> And if you still getting problems, try to add of one this library on the beginning of the code.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;time.h&gt; #include &lt;unistd.h&gt; #include &lt;dos.h&gt; #include &lt;windows.h&gt; </code></pre> <hr> <ul> <li><strong>system("PAUSE")</strong></li> </ul> <p>A simple "Hello world" programme on windows console application would probably close before you can see anything. That the case where you can use system("Pause").</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(void) { cout &lt;&lt; "Hello world!" &lt;&lt; endl; system("PAUSE"); return 0; } </code></pre> <p>If you get the message "error: 'system' was not declared in this scope" just add the following line at the biggining of the code :</p> <pre><code>#include &lt;cstdlib&gt; </code></pre> <hr> <ul> <li><strong>cin.ignore()</strong></li> </ul> <p>The same result can be reached by using cin.ignore() :</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(void) { cout &lt;&lt; "Hello world!" &lt;&lt; endl; cin.ignore(); return 0; } </code></pre> <hr> <ul> <li><strong>cin.get()</strong></li> </ul> <p>example :</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main(void) { cout &lt;&lt; "Hello world!" &lt;&lt; endl; cin.get(); return 0; } </code></pre> <hr> <ul> <li><strong>getch()</strong></li> </ul> <p>Just don't forget to add the library conio.h :</p> <pre><code>#include &lt;iostream&gt; #include &lt;conio.h&gt; //for using the function getch() using namespace std; int main(void) { cout &lt;&lt; "Hello world!" &lt;&lt; endl; getch(); return 0; } </code></pre> <p>You can have message telling you to use _getch() insted of getch</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload