473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Running exe file?

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
Jul 23 '05 #1
9 1824
Rashrashetta wrote:
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
Jul 23 '05 #2
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.

Jul 23 '05 #3
Victor Bazarov wrote:
Rashrashetta wrote:
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


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

Larry
Jul 23 '05 #4
Rashrashetta wrote:
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;
}


Thanx alot,
Rashrashetta

Jul 23 '05 #5
Ron Wills wrote:
Rashrashetta wrote:

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).

Jul 23 '05 #6
At 21 Jun 2005 17:15:21 -0700,
Old Wolf wrote:

Ron Wills wrote:
Rashrashetta wrote:

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.

Jul 23 '05 #7
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.

Jul 23 '05 #8
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!

Jul 23 '05 #9
ra*********@hotmail.com (Rashrashetta) wrote:
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.

--
Tim Slattery
Sl********@bls.gov
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fabio Pliger | last post by:
Hi, is it possibile, in python, to check for an already running instance of an application? My problem is that, if my program i running and the user relaunch it, i don't want to open a new...
6
by: Pierre-Yves | last post by:
Hello, I would like to prevent my perl program to be executed several times simultaneously (if the program is already running, I would like to display a message like "another instance of this...
15
by: Andrew Chalk | last post by:
I have just moved a project to my laptop and get the message "Visual Studio ..NET has detected that the specified Web server is not running ASP.NET v1.1. You will be unable to run ASP.NET Web...
3
by: jliusolar | last post by:
Hi I am trying to figure out why an application get this error when I am trying to open the application's asmx file from localhost. I don't have indexing service running(it set as manual and not...
8
by: Alphonse Giambrone | last post by:
I have a small asp.net web app running on a shared host. It uses a Jet (Access) database. I included a routine to compact the database when the application_event fires if it has not been compacted...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
5
by: mabond | last post by:
Hi recently read a posting and reply about Excel processs still running after the Appliction.Quit was called. Thought I might be able to use the same...
4
by: Michael Malinowski | last post by:
Is there a way to read the directory that the currently running python file is located in? Cheers Mike.
8
by: geert | last post by:
Hi all, I have a mac mini running maocosx 10.5 leopard I want to deploy a django project on. My backend is MySQL, and I have it running as a 64- bit app. Of course, apache2 is also running as...
1
by: =?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?= | last post by:
On reflection, you could possibly make the app a self extracting zip file which extracts the EXE and a settings file and then starts the app, then when you app closes, it can repack the settings...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.