![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
Banned
![]() ![]() |
Quote:
If there's something in the buffer (IE. After some instances of scanf), then it will skip right past the prompt.Both of these issues leave it to not behave the same way as system ("pause"), which is the desirable requirement in most instances. The system ("pause") is just meant to be there as an informal way to add a break to the end of the program. If the code was going to be serious enough to require portability, it would arguably never even need a break at the end in the first place. But if you wanted to replicate its behaviour, you would need to combine an event flush with something like GetAsyncKeyState, in order to remove the need to hit return. Which, I believe... is windows inclusive? If it's not windows inclusive, is that the best way to handle keystrokes without waiting for return, it seems a little extraneous? Never bothered to look up any alternatives to system ("pause"). I see no need really. Yeah, it's still Windows inclusive. Ain't it? Gimme a cheap way out of it! ![]() c Syntax (Toggle Plain Text)
Last edited by Sane; Nov 4th, 2006 at 10:24 AM. |
|
|
|
|
|
|
#12 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Jessehk's point was not to use system("pause") in code you post on forums. Posting it liberally in forums like this one implicitly encourages newbies to use it, and it is never a good idea to encourage non-portable techniques unless they are absolutely needed. Furthermore, in most of the examples where you use it, it is completely irrelevant to the problem at hand. Which means you are posting unnecessary information that implicitly encourages newbies to adopt bad practices.
As to a cheap solution under windows, that's easy. When you are creating an executable, all compilers create them in some directory (usually the path of your project, or some other directory that you configure, so you know where it is). I then do the following (assuming I have windows installed, with the windows directory being C:\WINNT and the path of executable being created being C:\whatever) 1) Create a desktop shortcut to C:\WINNT\System32\CMD.exe 2) Change properties of the shortcut so the directory it starts in is C:\whatever. To use that shortcut; 1) Doubleclick it. 2) Type in the name of the executable and hit Enter. The output from the executable will be displayed in the command window, even after the program exits. 3) Repeat step 2 whenever you want to run the executable. 4) Close the command window when no longer required. It takes a bit more effort to do this than using system("pause") in your program, but it only needs to be setup (at most) once for every project. |
|
|
|
|
|
#13 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
I agree with all the portability issues grumpy said above. Don't most IDE's do this automatically, I mean run the program in such a way that is "pauses" after execution.
|
|
|
|
|
|
#14 | ||
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,197
Rep Power: 5
![]() |
Quote:
Quote:
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
||
|
|
|
|
|
#15 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Quote:
And, Game_Ender, the reason this comes up as an issue is that most IDE's do not run a console application in a way that pauses after they finish execution. Hence the common workaround is to get the program to wait for input; unfortunately the method that people tend to wish for is equivalent to the microsoft "pause" command, and there is no portable way (but plenty of non-portable ways) to achieve that in C/C++. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| relation between array and pointer | n00b | C++ | 6 | Oct 12th, 2006 4:38 PM |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 6:41 PM |
| create struct from value of a variable | mfo6463 | C++ | 18 | Feb 9th, 2006 10:45 AM |
| Assigning first character of variable into an array | IceNeo | Visual Basic .NET | 1 | Nov 10th, 2005 1:13 PM |
| Installing IPB 2.03 | bh4575 | Other Web Development Languages | 0 | Apr 23rd, 2005 3:36 AM |