my hello world program closes right after it opens

hi i am new to c++ and i just installed it yesterday but i did not get much time to use it.i just put a hello world program in it with dev c++ but once i started it, it closed very fast. this is probaly a noob problem but thanks anyways

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}
try to put this at the end:
1
2
int a;
cin>>a;

I use this in my console apps.
Or try to start your app from Command Promt
Last edited on
i put it before the return 0; and it did not work, did you mean for me to put it somewhere else?
dear sir,
kindly try this
#include <iostream>
#include<conio>

void main ()
{
cout << "Hello World!";
getch();
}
regards
matanuragi
no it did not work but thank you anyways
i found something that works
<conio.h> is a library that is only included in a Borland compiler. Try:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;

int main ()
{
cout << "HELLO WORLD!! ";
cout << "Press ENTER to continue...\n";
cin.get();
return 0;
}
Last edited on
If you're on windows, you can use a nice little system("pause"); command.


Not really portable though.
the system("Pause") command displays that annoying "Press ENTER to continue..." thing. Try using cin.get(); right before the end of the code
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
return 0;
}

becomes
1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";
cin.get();
return 0;
}
dear sir,
kindly try this

#include <iostream>
#include<conio>
using namespace std;

int main ()
{
cout << "Hello World!";
getch():
return 0;
}

with regards,
matanuragi
@matanuragi
No one here is so stupid that you have to repeat yourself. <conio.h> is a non-portable library in any case.

@alexcook
There is a thread at the top of this forum entitled Console Closing Down. It deals specifically with your problem.

Good luck.
Topic archived. No new replies allowed.