The Daily Click ::. Forums ::. Non-Klik Coding Help ::. it closes instantly
 

Post Reply  Post Oekaki 
 

Posted By Message

Destroyer (CrobaSoft)



Registered
  10/10/2004
Points
  1106
25th February, 2005 at 15:42:39 -

i finnaly decided to start learning c++, but i got stock right from the begging.
i entered this into c++

#include <iostream>

using namespace std;

int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();
}

then saved it as a txt file opened it in dev, saved it and then clicked compile and run. then it just closes instantly. i can just bairly see a dos window and then it close.
i tried halting it with a while loop but that gaved me some cryptic error

 
Visit www.crobasoft.com or you're a Noob.

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
25th February, 2005 at 15:58:05 -

try:


#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();
system("PAUSE");
}


Just curious, what did your while loop look like?

Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Destroyer (CrobaSoft)



Registered
  10/10/2004
Points
  1106
25th February, 2005 at 16:06:47 -

thanks that worked great.
my while loop looked like
#include <iostream>

using namespace std;

int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
cin.get();
}
while(1);

i dont know if it's different in c++ but i just thought it was worth a try

 
Visit www.crobasoft.com or you're a Noob.

Destroyer (CrobaSoft)



Registered
  10/10/2004
Points
  1106
25th February, 2005 at 16:11:13 -

oh now i get it. i should have putten the while loop in to the int main()

 
Visit www.crobasoft.com or you're a Noob.

Long John Kickbag



Registered
  26/08/2002
Points
  148
25th February, 2005 at 16:33:12 -

You know you are required to return a value if you set a return type, make sure you use void if you aren't planning on returning anything.

 
Resize! - www.clicksplat.com/comparison.html

Destroyer (CrobaSoft)



Registered
  10/10/2004
Points
  1106
26th February, 2005 at 05:09:05 -

doesnt int main() automaticlly returns zero

 
Visit www.crobasoft.com or you're a Noob.

David Newton (DavidN)

Invisible

Registered
  27/10/2002
Points
  8322

Honored Admin Alumnus
26th February, 2005 at 05:49:50 -

That's what I thought, but I always tend to put return(0) at the end of mine just in case. In case of what, I don't know.

 
http://www.davidn.co.nr - Games, music, living in America

Klikmaster

Master of all things Klik

Registered
  08/07/2002
Points
  2599

Has Donated, Thank You!You've Been Circy'd!VIP MemberPS3 Owner
26th February, 2005 at 07:39:08 -

You're meant to put return 0, but it might not be required

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
26th February, 2005 at 09:09:17 -

ISO standards say you should do "int main" and "return (whatever)" but most compilers don't care and just turn it into "void main" if you forget to "return"

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Tigerworks

Klik Legend

Registered
  15/01/2002
Points
  3882
26th February, 2005 at 12:22:43 -

C/C++ never do anything unless you tell it. No functions automatically return, you must tell them to. Hence main must return 0 at the end.

 
- Tigerworks

Radix

hot for teacher

Registered
  01/10/2003
Points
  3139

Has Donated, Thank You!VIP MemberGOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!
26th February, 2005 at 19:36:53 -

That depends on your compiler.

 
n/a

DaVince

This fool just HAD to have a custom rating

Registered
  04/09/2004
Points
  7998

Game of the Week WinnerClickzine StaffHas Donated, Thank You!Cardboard BoxDos Rules!
1st March, 2005 at 14:50:28 -

Putting cin.get() twice worked for me...

haha, that's a cprogramming.com example!

 
Old member (~2004-2007).
   

Post Reply



 



Advertisement

Worth A Click