Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


.exe files closing immediately.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
SirSteez
Newbie cheater
Reputation: 0

Joined: 10 Nov 2007
Posts: 19

PostPosted: Wed Jan 30, 2008 12:19 am    Post subject: .exe files closing immediately. Reply with quote

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
View user's profile Send private message
guernica
Grandmaster Cheater Supreme
Reputation: 0

Joined: 20 Jun 2007
Posts: 1211

PostPosted: Wed Jan 30, 2008 12:24 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
iCucco
Advanced Cheater
Reputation: 0

Joined: 11 May 2007
Posts: 51
Location: 0x0600

PostPosted: Wed Jan 30, 2008 7:32 am    Post subject: Reply with quote

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
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Wed Jan 30, 2008 7:34 am    Post subject: Reply with quote

Or just run it with cmd
Start => run => "cmd" => Run!
Code:
cd folder/of/ya/prog
hello-world.exe
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Wed Jan 30, 2008 8:58 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Jan 30, 2008 9:20 am    Post subject: Reply with quote

Or you can just run it from the actual command prompt if you're feeling extra saucy.
Back to top
View user's profile Send private message
SirSteez
Newbie cheater
Reputation: 0

Joined: 10 Nov 2007
Posts: 19

PostPosted: Thu Jan 31, 2008 12:31 am    Post subject: Reply with quote

haha alright thanks guys i'll try those.
Back to top
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Thu Jan 31, 2008 12:36 am    Post subject: Reply with quote

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
View user's profile Send private message
SirSteez
Newbie cheater
Reputation: 0

Joined: 10 Nov 2007
Posts: 19

PostPosted: Thu Jan 31, 2008 12:42 am    Post subject: Reply with quote

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
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Thu Jan 31, 2008 12:45 am    Post subject: Reply with quote

You dont prototype main. What compiler do you use?
_________________

Earthbound = 31337
Back to top
View user's profile Send private message
SirSteez
Newbie cheater
Reputation: 0

Joined: 10 Nov 2007
Posts: 19

PostPosted: Thu Jan 31, 2008 12:48 am    Post subject: Reply with quote

Losplagos wrote:
You dont prototype main. What compiler do you use?


C++BuilderX

made by Borland
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Thu Jan 31, 2008 4:08 am    Post subject: Reply with quote

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
View user's profile Send private message
iCucco
Advanced Cheater
Reputation: 0

Joined: 11 May 2007
Posts: 51
Location: 0x0600

PostPosted: Thu Jan 31, 2008 4:35 am    Post subject: Reply with quote

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
Code:
return 0;
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
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Thu Jan 31, 2008 7:40 am    Post subject: Reply with quote

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
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Thu Jan 31, 2008 7:54 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites