| View previous topic :: View next topic |
| Author |
Message |
SirSteez Newbie cheater
Reputation: 0
Joined: 10 Nov 2007 Posts: 19
|
Posted: Wed Jan 30, 2008 12:19 am Post subject: .exe files closing immediately. |
|
|
Alright so I just bought a C++ book and finished Hello World.exe BUT whenever I double click it to run the file, the CMD Prompt opens up and closes immediately after, so I can't see anything.
Does anyone know how I can make it so the CMD Prompt doesn't immediatly shut down, or is this normal?
|
|
| Back to top |
|
 |
guernica Grandmaster Cheater Supreme
Reputation: 0
Joined: 20 Jun 2007 Posts: 1211
|
Posted: Wed Jan 30, 2008 12:24 am Post subject: |
|
|
| Code: | cin.ignore();
cin.get();
return 0; |
at the end of your main function
_________________
| georgezilka wrote: | | im looking for experience (EXP) hacks for maple story are there any where it can give instant level up ? |
|
|
| Back to top |
|
 |
iCucco Advanced Cheater
Reputation: 0
Joined: 11 May 2007 Posts: 51 Location: 0x0600
|
Posted: Wed Jan 30, 2008 7:32 am Post subject: |
|
|
Actually, | Code: |
system("pause");
//Requires windows.h
|
or | Code: |
getch();
return 0;
//Requires conio.h
|
works as well. If you want just to keep it open, use | Code: |
Sleep(INFINITE);
//Requires windows.h
|
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Wed Jan 30, 2008 7:34 am Post subject: |
|
|
Or just run it with cmd
Start => run => "cmd" => Run!
| Code: | cd folder/of/ya/prog
hello-world.exe |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Wed Jan 30, 2008 8:58 am Post subject: |
|
|
| iCucco wrote: | Actually, | Code: |
system("pause");
//Requires windows.h
|
or | Code: |
getch();
return 0;
//Requires conio.h
|
works as well. If you want just to keep it open, use | Code: |
Sleep(INFINITE);
//Requires windows.h
|
|
Avoid System("pause"); all it does is creates a huge overhead in your program which you don't need or want.
http://www.gidnetwork.com/b-61.html
And guernica's example was fine. That is one of the more preferred methods.
_________________
- Retired. |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Jan 30, 2008 9:20 am Post subject: |
|
|
| Or you can just run it from the actual command prompt if you're feeling extra saucy.
|
|
| Back to top |
|
 |
SirSteez Newbie cheater
Reputation: 0
Joined: 10 Nov 2007 Posts: 19
|
Posted: Thu Jan 31, 2008 12:31 am Post subject: |
|
|
| haha alright thanks guys i'll try those.
|
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Thu Jan 31, 2008 12:36 am Post subject: |
|
|
Personally i like using a loop, bool, and a switch on most programs that i can make repeat to use again.
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
SirSteez Newbie cheater
Reputation: 0
Joined: 10 Nov 2007 Posts: 19
|
Posted: Thu Jan 31, 2008 12:42 am Post subject: |
|
|
haha alright thanks guys i'll try those.
where would i insert those in
| Code: |
#include <iostream>
int main();
int main()
{
std::cout << "Hello World!\n";
return 0;
}
|
and is having both the "int main()"'s necessary?
I tried putting in the Sleep(INFINITE); right after return 0; and that didn't work.
I also tried guernica's method after the } and also tried replacing it with the current return 0;, neither worked.
In cmd prompt I went to the .exe's destination folder and tried running the program there but it said "'hello world.exe' wasn't recognized as an internal or external command or as an operable program or batch file.
although i found out keeping cmd prompt open isn't really necessary, for my compiler shows what the program does below the source.. >_<
|
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Thu Jan 31, 2008 12:45 am Post subject: |
|
|
You dont prototype main. What compiler do you use?
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
SirSteez Newbie cheater
Reputation: 0
Joined: 10 Nov 2007 Posts: 19
|
Posted: Thu Jan 31, 2008 12:48 am Post subject: |
|
|
| Losplagos wrote: | | You dont prototype main. What compiler do you use? |
C++BuilderX
made by Borland
|
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Thu Jan 31, 2008 4:08 am Post subject: |
|
|
This how i run console applocation:
Put the following code in batch file: | Quote: | echo off
@echo Insert file to run
Set LunchP=
SET /P LunchP=
cls
%LunchP%
pause>nul |
Run it and drag the exe file into it.
|
|
| Back to top |
|
 |
iCucco Advanced Cheater
Reputation: 0
Joined: 11 May 2007 Posts: 51 Location: 0x0600
|
Posted: Thu Jan 31, 2008 4:35 am Post subject: |
|
|
| SirSteez wrote: | haha alright thanks guys i'll try those.
where would i insert those in
| Code: |
#include <iostream>
int main();
int main()
{
std::cout << "Hello World!\n";
return 0;
}
|
and is having both the "int main()"'s necessary?
I tried putting in the Sleep(INFINITE); right after return 0; and that didn't work.
I also tried guernica's method after the } and also tried replacing it with the current return 0;, neither worked.
In cmd prompt I went to the .exe's destination folder and tried running the program there but it said "'hello world.exe' wasn't recognized as an internal or external command or as an operable program or batch file.
although i found out keeping cmd prompt open isn't really necessary, for my compiler shows what the program does below the source.. >_< |
It doesn't work because is the exit call for the main thread. If you put code after that call, it will not be executed. Put it this way: | Code: | | Sleep(INFINITE); return 0; |
Although it's not necessary to put in "return 0;" if you are planning to use Sleep(INFINITE) it's better to be sure that your program is terminated if something unusual happens.
As for the code: | Code: |
#include <iostream>
#include <windows.h>
#define WIN32_LEAN_AND_MEAN
using namespace std;
int main()
{
cout << "Hello World!"<<endl;
Sleep(INFINITE);
return 0;
} |
@Wiccaan: You're absolutely right, system("pause"); is awful way of stopping the application, but it is a method to do that anyways.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Jan 31, 2008 7:40 am Post subject: |
|
|
| rEakW0n wrote: | Or just run it with cmd
Start => run => "cmd" => Run!
| Code: | cd folder/of/ya/prog
hello-world.exe |
|
this method is annoying
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Thu Jan 31, 2008 7:54 am Post subject: |
|
|
| Rot1 wrote: | | rEakW0n wrote: | Or just run it with cmd
Start => run => "cmd" => Run!
| Code: | cd folder/of/ya/prog
hello-world.exe |
|
this method is annoying |
Why?
I don't get it. You always gotta bitch at my posts.
|
|
| Back to top |
|
 |
|