Running exe file?

R

Rashrashetta

Hai all,

I just want to ask, after compiling and executing a certain program in
C++, when I try to run the .exe file, it displays the output and close
very fast in a way that I can't read what have been written in the
screen...Why does this happen? and how to fix it?


Thanx alot,
Rashrashetta
 
V

Victor Bazarov

Rashrashetta said:
I just want to ask, after compiling and executing a certain program in
C++, when I try to run the .exe file, it displays the output and close
very fast in a way that I can't read what have been written in the
screen...Why does this happen? and how to fix it?

Put some input at the very end of the 'main' function, which would
stop the program so you can look at the output. I usually do something
like

...
std::cout << "Press Enter..." << std::flush;
std::string dummy;
std::getline(std::cin, dummy);
}

V
 
M

mattsniderppl

There is probably an error in your program and an exit call. If you do
not have a program with a debugger than can move line by line, then I
would insert some

cout<<"test : did I get here"<<endl;
system("PAUSE");

in key spots throughout your code to find out which line is causing the
program to quit.
 
L

Larry I Smith

Victor said:
Put some input at the very end of the 'main' function, which would
stop the program so you can look at the output. I usually do something
like

...
std::cout << "Press Enter..." << std::flush;
std::string dummy;
std::getline(std::cin, dummy);
}

V

Or start a "Command Prompt" and run the program from there perhaps?

Larry
 
R

Ron Wills

Rashrashetta said:
Hai all,

I just want to ask, after compiling and executing a certain program in
C++, when I try to run the .exe file, it displays the output and close
very fast in a way that I can't read what have been written in the
screen...Why does this happen? and how to fix it?

Include a sleep() statement before the output is destroyed.

#include <cstdlib>

int main(int argc, char *argv[]) {
...

std::sleep(5); // Sleep for 5 seconds
return 0;
}
 
O

Old Wolf

Ron said:
Rashrashetta said:
I just want to ask, after compiling and executing a certain program in
C++, when I try to run the .exe file, it displays the output and close
very fast in a way that I can't read what have been written in the
screen...Why does this happen? and how to fix it?

Include a sleep() statement before the output is destroyed.

#include <cstdlib>

int main(int argc, char *argv[]) {
...

std::sleep(5); // Sleep for 5 seconds
return 0;
}

There is no C++ standard function 'sleep' (perhaps you're getting
the POSIX function by that name, if that code works for you).
 
R

Ron Wills

At 21 Jun 2005 17:15:21 -0700,
Old said:
Ron said:
Rashrashetta said:
I just want to ask, after compiling and executing a certain program in
C++, when I try to run the .exe file, it displays the output and close
very fast in a way that I can't read what have been written in the
screen...Why does this happen? and how to fix it?

Include a sleep() statement before the output is destroyed.

#include <cstdlib>

int main(int argc, char *argv[]) {
...

std::sleep(5); // Sleep for 5 seconds
return 0;
}

There is no C++ standard function 'sleep' (perhaps you're getting
the POSIX function by that name, if that code works for you).

Opps, looks like your right :p. Just goes to show, never make
assumptions ;). Should be using stdlib.h.
 
Z

Zara

I should propose to put the following lines at the end of main():

std::cout<<"Press a key to end program"<<std::endl;
char dummy;
std::cin.get(dummy);


This will wait for a key press (any key press!) and then exit, and it
is completely portable. Only in case you redirect standar input, you
must take some caution.
 
Z

Zara

Sorry, it won´t work with any key, it still needs the return key to
work.
May I say we are working with the A/C broken (whole day at 30ºC) as an
excuse?

Nice day, not too hot, to all!
 
T

Tim Slattery

Hai all,

I just want to ask, after compiling and executing a certain program in
C++, when I try to run the .exe file, it displays the output and close
very fast in a way that I can't read what have been written in the
screen...Why does this happen? and how to fix it?

I'd guess that you're using a Windows OS and you're running the
program by using Start|Run. Instead, open a command console ("DOS
Box"). That should be in your Start menu someplace, try Start|All
Programs|Accessories|Command Prompt. That window will stay open when
your program closes. Unless your program is doing something to clear
the screen before closing, you should be able to see the output.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,536
Members
48,282
Latest member
Xyprime

Latest Threads

Top