Problems With Executing A Program

shoover1

Baseband Member
Messages
22
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...
 
Dude I don't really know. Try this:
Code:
//Blah Blah
#include<iostream>
using namespace std;

void main()
{
cout << "Hey there" << endl;
system("PAUSE");
}
 
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!
 
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.
 
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.
 
Back
Top Bottom