Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 04-17-2008, 07:15 PM   #1
Baseband Member
 
Join Date: Jun 2006
Posts: 22
Default Problems With Executing A Program

Hi Everybody!

I have question that regards to cmd.exe. This is also a problem to running other programs under .exe, but whenever i execute a program I made, I see the CMD box, but then it just automatically closes after a third of a second, I thought at first my cmd.exe had the /c extension at the end of it, but I dont see it anywhere.

Does anybody know why this is happening to me? I mean all I did was a little Test program:

--------------------

/*Bla Bla*/

#include <iostream>
using namespace std;

int main()
{
cout << "hello" << endl;
return(0);
}

---------------------

It ran with no errors etc...
__________________

shoover is offline   Reply With Quote
Old 04-17-2008, 08:08 PM   #2
Guru
 
JogaBonito1502's Avatar
 
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: Problems With Executing A Program

Dude I don't really know. Try this:
Code:
//Blah Blah
#include<iostream>
using namespace std;

void main()
{
cout << "Hey there" << endl;
system("PAUSE");
}
__________________

JogaBonito1502 is offline   Reply With Quote
Old 04-17-2008, 08:24 PM   #3
Baseband Member
 
Join Date: Jun 2006
Posts: 22
Default Re: Problems With Executing A Program

lol thats weird, I take a programming class in school and we use c++ 6.0. I guess I have to make changes because that works. Thanks!
shoover is offline   Reply With Quote
Old 04-17-2008, 08:49 PM   #4
Guru
 
JogaBonito1502's Avatar
 
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Re: Problems With Executing A Program

I also take a programming class. And I did pretty much the same thing. system("pause") just stops the program after outputting. Them problem was that it submitted hello and it ended the program. System pause makes it wait.
JogaBonito1502 is offline   Reply With Quote
Old 04-18-2008, 02:00 PM   #5
Fully Optimized
 
Š88's Avatar
 
Join Date: May 2005
Posts: 4,775
Send a message via MSN to Š88
Default Re: Problems With Executing A Program

Quote:
Originally Posted by JogaBonito1502 View Post
Dude I don't really know. Try this:
Code:
//Blah Blah
#include<iostream>
using namespace std;

void main()
{
cout << "Hey there" << endl;
system("PAUSE");
}
that works to keep the program up so you can see the output but that also means the program never quits. It stays open until you manually close it.

Try running the executable within a shell (command prompt) so it doesn't close afterwards.

This works also

Code:
#include <iostream>
using namespace std;

int main()
{
cout << "hello" << endl;
Sleep(20); // pauses the program (in this case for 20ms)
return(0);
}
i believe windows requires the <windows.h> header for Sleep to work as well.
__________________
Killing under the cloak of war is no different than murder

Kein Alkohol ist auch keine Lösung!
Š88 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 10:29 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0