Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 07:47 AM

Hay guys;

as the title states, I've been having an issue with the display window. As you rebuild and run the program. It will not give any sort of error but it will successfully rebuild and compile. Tho, the display window will flicker instead of what it suppose to do. Which is, it should stay open.
Now the code that I've been using is working out for me so far, but there has to be another way.

Re: Visual C++ Express 2010 compile and pausing the display issue

Posted 09 December 2011 - 08:16 AM

Two ideas:
(1) In Visual Studio, click on "Project", and then "Properties" (the last item in the drop-down menu.

That opens up the "Property Pages" menu.
Then, click on Configuration Properties/Linker/System, and in the right column click on SubSystem which will open a drop-down box. In that box, click on the first item "CONSOLE (/SUBSYSTEM:CONSOLE)"

Click OK to close the PropertyPages.

When you run your program, use Ctrl-F5 or "Start without Debugging."

That will hold the VS terminal window open after the program finishes.

Oh, and definitely don't start using conio and getch, which were never part of C or C++ standards and will make your programs non-portable to other systems.

(2) The windows command prompt doesn't behave at all like the MS Visual Studio terminal window. Specifically, the command prompt window never closes just because a program finished running -- it remains open waiting for another command. So if you're having this problem with the command prompt, it sounds like you're trying to prevent YOUR program from ending. That's a different matter -- which, as Jim said, cin.get() should solve.

Re: Visual C++ Express 2010 compile and pausing the display issue

I tried running it in command prompt by going in to the directory and simply typing the file with cpp extension.

That's not the same as running it in a command window. To do that, you first build (but don't run) the program in MSVS by clicking Build/Build solution on the menubar, or just press F7.

Then open a command window by clicking (on the Windows taskbar) Start/run, which opens the Run dialog box, and then type cmd and click OK.

Now you'll see a command (terminal) window with a command prompt (usually C:\Documents and Settings\[your username]> ). In the command window, navigate to the folder where MSVS stored the .exe file for your program (using cd to change directories as necessary), and then type the name of the .exe file, followed by enter.

-----------

Regarding the project configuration in MSVS, here's how you can avoid that when starting a new project:

Open the New Project window, select Win32 Console Application, type a project name & click OK

On the next window, under "Additional options", click Empty project. Now click Finish.

To add a file to the project (this applies to your initial program (.cpp) file as well as any additional header and source files you want to add to the project) click Project/Add New Item and select the type of file you're adding (initially, C++ File), enter a name for the file, and click Add

You now have an empty file in which to write your program. When ready to test your program, build it by pressing F7, then run it by typing Ctrl-F5 (that means press and hold the Control key while you press the F5 key) and the terminal window will stay open when the program finishes.

First, void main() is ALWAYS WRONG in C++...ALWAYS! main MUST return an int.
Second, conio is a non-standard header, and getch() is a non-standard function. Do not suggest their use when a suitable standard replacement for this functionality exists.