Quickie - VS 2003 C++ compiler option to keep console open?
Is there a VS 2003 C++ compiler option that keeps a console application open after it has finished running?
Yeah I know I could just use cin or something at the end, but I just want that console window to stay open until I close it so I can see what it's output. I'm sure I've used the feature before, but probably in a different compiler & IDE.
Cheers,
Paul
If you select "start without debugging" (ctrl+f5) the console will stay open, if you select "start" (F5) the console will close.
If you run it from the command line, or a batch file, the console should also remain when the program has terminated.
If I want it to stay open with F5 I usually just stick a breakpoint on the closing brace of main() but if there's a better way I'd love to know it. I thought I'd come across the option once before (perhaps with VC6?) but I've hunted for it in VS .NET 2003 to no avail.
int main() { system("PAUSE");}
It requires no special headers or whatnot, just tack it onto the end and you get the "Press any key to continue..." thing just like if you select "Start without debugging"
CM
Quote:Original post by Nemesis2k2
Actually, that requires the windows.h header to be included.
Quote:My SYSTEM(3) manpage
SYSTEM(3) Linux Programmer's Manual SYSTEM(3)
NAME
system - execute a shell command
SYNOPSIS
#include <stdlib.h>
int system (const char * string);
[...]
CONFORMING TO
ANSI C, POSIX.2, BSD 4.3
My emphisises (?). This means #include <cstdlib> for C++, and find system in the std:: namespace.
Quote:Original post by MaulingMonkey
My emphisises (?). This means #include <cstdlib> for C++, and find system in the std:: namespace.
I don't think any of the functions from C is wrapped in namespaces, so the std:: part isn't needed.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement