Hey, whenever I write a C++ program it flashes the window for 1 second then it goes away. When i add SYSTEM("PAUSE") at the end it starts to work but I don't want to have to do that every time and in and out of my source code. Is there any other solution?
Write a simple method to a class named Environment, let's say, "enter_to_go();" displaing the message - "hit enter to go ahead." and every time you need a pause, write in the code "enter_to_go();" or something shorter.
I have it here the class is Ambiente.h (sorry, mainly in Portuguese) and the method
is apeteco2() - which means "hit enter to go".
Visual Studio has two types of builds: Debug and Release.
The default build is Debug and that means code is inserted in the .exe to support the debugging files. The Release build has not debugger support.
When you execute a program using Start (F5), Visual Studio sees that it is a debug .exe and assumes you have the necessary pauses already inserted. If you don't, you see a black flash which is the console screen going by as your program executes.
You may also execute your program using Start Without Debugging (CTRL+F5). WWhen you do this, you tell Visual Studio that while this is a debuge .exe, you are not using your debugger. In this case, Visual Studio will pause at the end of main() with:
Press any key to continue...
Therefore, you never need any special code in your program for testing.
Hey, CTRL+F5 seems to work but where does it save the exe that is NOT injected. When I locate the exe in My Doctuments >> Visual Studio 2005 >> Projects >> Project 1 >> Debug >> Project1.exe it flashes in and out.
That's because you are executing the program outside of Visual Studio.
That black console window you see in Visual Studio is not the command interpreter. It is a black window generated by Visual Studio to make you think it's the command interpreter- but it ain't. It's a special window controlled by Visual Studio so the F5 vs. CTRL+F5 works.
In fact your .exe is a debug .exe without pauses. When you execute directly using the command interpreteer, you get no pauses.
OK, wel I heard somewhere that when you program for windows then it will have pauses automatically just because of the window and everything. Is that true? And also, if I am to put pauses in how would I pause in the middle of a program?
A Windows program is not a ANS/ISO C++ program. It does not use main(). Your Windows programs runs under the auspices of the operating system plsu whatever API your are using. Pauses couild very well be automatically inserted.
What kind of pause do you need?
1) The user needs to respond: use a cin>> and check for Y or N
2) The user does not need to respond AND your are using Windows, try Sleep(seconds);
Otherwise, you can create a Windows Console Application and use message boxes.