|
From: Chris M. <lor...@gm...> - 2008-12-24 07:34:29
|
On Tue, Dec 23, 2008 at 8:10 PM, c william <not...@ya...> wrote:
> Hello all,
>
> I am very, very new to programming and needless to say I am having trouble
> with the simplest "Hello World" program. It compiles OK, but when it runs
> on Dev-CPP the ouptut window only stays open for a fraction of a second. Is
> there a setting that I am missing?
The (stupid) Windows terminal is closing before you can see the
output. You need to pause it.
> Below is the code:
>
> #include<iostream>
#include<cstdlib>
> using namespace std;
>
> int main()
> {
> cout << "Hello World\n";
system("PAUSE");
> return 0;
> }
>
> I certainly hate bothering anyone with such a trivial request, but it is
> probably something so simple that an experienced programmer would spot in a
> flash. Thanks in advance!
It's not obvious, and to give you the more correct solution (should
you choose to use it):
char c;
std::cout << "Press the any key to continue... " << std::endl;
std::cin.get(c);
return 0;
This method is more "correct" because system("PAUSE"); only works on
Windows, whereas the whole cin.get routine works on Windows, Linux,
Mac, and everything else AFAIK.
--
Registered Linux Addict #431495
http://profile.xfire.com/mrstalinman | John 3:16!
http://www.fsdev.net/ | http://lordsauron.wordpress.com/
Parents, Take Responsibility For Your Kids! http://www.whattheyplay.com/
|