English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I am an amateur trying to learn C++. I complie my first prgram, it gives no errors, but when I run it, the output screen disappears so quickly that I barely get a glance of the output. Please help.

2006-10-28 12:40:28 · 8 answers · asked by Razor 5 in Computers & Internet Programming & Design

No, I am not using visual C++. In fact it's the traditional Turbo C++.

2006-10-28 12:51:34 · update #1

8 answers

Add getch(); in the last row before you close the main footer.

int main(){
//YOUR PROGRAM
getch();
return 0;
}

If you're using Turbo C++, press Alt+F5 to look at output screen.

peace
vixklen

2006-10-28 16:35:16 · answer #1 · answered by vixklen 3 · 3 0

"i have not in any respect understood why equipment("PAUSE") is so customary. particular that is going to pause a software till now it exits. This pause is amazingly functional even as your IDE received't wait as you attempt a software and once this methodology finished the window closes taking all of your files with it. yet utilising equipment("PAUSE") is like burning your fixtures for heat once you've a superbly good thermostat on the wall. many human beings, instructors lined, for some inexplicable reason imagine that making a decision to the operating equipment and operating a equipment command to briefly halt a software is a good component. the position they get this theory is previous me. motives: that is not transportable. This works in basic terms on structures which have the PAUSE command on the equipment aspect, like DOS or abode windows. yet not Linux and maximum others... that is an extremely expensive and source heavy function call. that is like utilising a bulldozer to open your the front door. it quite works, in spite of the indisputable fact that the most important's purifier, a lot less complicated, more cost-efficient. What equipment() does is: droop your software call the operating equipment open an operating equipment shell (relaunches the O/S in a sub-procedure) the O/S might want to now locate the PAUSE command allocate the reminiscence to execute the command execute the command and look ahead to a keystroke deallocate the reminiscence go out the OS resume your software There are a lot purifier techniques lined contained in the language itself that make all this unnessesary. you may want to contain a header you in all likelihood do not want: stdlib.h or cstdlib it really is a nasty habit that is necessary to break finally besides. particularly, use the needs that are defined natively in C/C++ already. So what's it you attempt to do? look ahead to a key to be pressed? high quality -- it really is named enter. So in C, use getchar() particularly. In C++, how about cin.get()? All you should do is press go back and your software maintains" it really is in accordance with the guy above me...

2016-12-05 08:08:25 · answer #2 · answered by ? 4 · 0 0

You might be using some IDE like visual C++ or something similar. What happens is that you don't have a break at the end of the program so it terminates after displaying the results. You can use the function getch() ( waits for one character at the command line ) which means once the result is displayed, just press any key to exit.

2006-10-28 12:46:20 · answer #3 · answered by Manish 5 · 2 1

use a .bat file (this work only if your OS is windows xp included )

1. create a new text file and rename it to script.bat it will display a warning, accept(in folder setting choose to show file extensions if you can't see the .txt part or don't get the warning)
2. edit the file in notepad and add the follwing code:
@echo off
//replace with path of your program compiled version
c:\mypro.exe
pause

3. just save and click on the bat file it will display :"Press any key to continue.....".
As long as your program name is constant the bat file will work!

OR...
You could run cmd.exe in xp or your command prompt command.com e.t.c (this works in linux too.)
then drag and drop your program onto the screen and press enter.

You could simplify your task by addind your ouput directory into the path environment variable
Like so:
in windows 9x:
Whenever you add a new value to the list of values for an
environment variable, use a semicolon to separate it. For example:

C:\DJGPP\BIN;other_values


The exact way how these variables should be set depends on your
operating system:

* For Windows 98 systems:

- Click START;
- Choose Programs->Accessories->System Tools->System Information;
- Click Tools in the menu-bar, then choose "System Configuration";
- Use the tab provided there for editing your AUTOEXEC.BAT as
explained below (i.e., use the "set" commands for BAT files
as described at the end of this list).

* For Windows ME systems:

- Click START, choose Run, type msconfig.exe, click OK;
- Click the "Environment" tab;
- Edit the PATH system variable to add the C:\DJGPP\BIN subdirectory
(remembering to use a semicolon to separate this directory from
the others);
-

* For Windows NT systems:

- Right-click "My Computer", then select "Properties";
- Click the "Environment" tab;
- Edit the PATH system variable to add the C:\DJGPP\BIN subdirectory;
(if you are not an administrator, add the C:\DJGPP\BIN directory to
the user PATH variable - or create one with only this directory
since it is added to the system path);


* For Windows 2000 or Windows XP systems:

- Right-click "My Computer", then select "Properties";
- Select the "Advanced" tab, then click "Environment Variables" button;
- Edit the PATH system variable to add the C:\DJGPP\BIN subdirectory;
(if you are not an administrator, add the C:\DJGPP\BIN directory to
the user PATH variable - or create one with only this directory
since it is added to the system path);

* For all other systems (DOS, Windows 3.X and Windows 95): use any
text editor, e.g., the standard EDIT, to edit the file
AUTOEXEC.BAT in the root directory of the boot drive (usually,
C:).

Instead of editing your autoexec files and/or global environment,
you may wish to create a djgpp shortcut instead. To do this, create
a BAT file which has the lines below in it. This is often needed if
you have multiple compilers on the same system.


the environment variables DJGPP and PATH should be set like this:
set PATH=C:\DJGPP\BIN;%PATH%
DJGPP is my programming path and bin is my output path.
(sorry for the long answer)
(naturally since you say "I am an amateur trying to learn C++" i am assuming you are writing a command line program)

2006-10-28 20:31:49 · answer #4 · answered by student 2 · 2 1

Set a breakpoint near the end of the program.

2006-10-28 12:51:08 · answer #5 · answered by Lisa A 7 · 1 1

before the end of the program, the last thing in main() add this:
getch();
it'll make it pause and wait for you to press enter.

2006-10-28 14:26:43 · answer #6 · answered by n0body 4 · 2 0

add cin.get(); or getch(); where you want it to pause.

2006-10-28 13:43:01 · answer #7 · answered by Rached N 2 · 4 0

if u are using dev-c++

use that:

SYSTEM("PAUSE");

2006-10-28 14:00:49 · answer #8 · answered by ibrahim ersoy 2 · 2 1

fedest.com, questions and answers