cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Beginners : my hello world program closes right afte...
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programm...
Articles
Lounge
Jobs

-

post  my hello world program closes right after it opens

alexcook (9)
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;
}
|
Nandor (83)
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
alexcook (9)
i put it before the return 0; and it did not work, did you mean for me to put it somewhere else?
|
matanuragi (22)
dear sir,
kindly try this
#include <iostream>
#include<conio>

void main ()
{
cout << "Hello World!";
getch();
}
regards
matanuragi
|
alexcook (9)
no it did not work but thank you anyways
|
alexcook (9)
i found something that works
|
QWERTYman (255)
<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
tombert (10)
If you're on windows, you can use a nice little system("pause"); command.


Not really portable though.
|
strongfan (5)
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;
}
|
matanuragi (22)
dear sir,
kindly try this

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

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

with regards,
matanuragi
|
Duoas (1596)
@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.
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2009 - All rights reserved - v2.2
Spotted an error? contact us