im noob herejust startin reading about c++... im doin d basic tutorials but as i said, command prompt just flashes.. i tried to make a batch filefor it like for example at notepad:
exercise.exe
pause
then saved it as exercise.bat
this works in some basic tutorials but in others more complicated it doesnt work coz it shows command prompt sayin "press any key to continue"
help this noob pls thnx
C++.. if i try to run it, the command prompt just flashes?
forget the batch file thing! just put getch() as the last line of your code (in your main), or before any return statement (in main). works EVERY time.
Reply:Answer to your other post about this problem.
Here is the code again.....
//Pre-Processor directives
#include %26lt;iostream%26gt;
#include %26lt;conio.h%26gt; // for getch();
//Specified namespace
using namespace std;
int main()
{
//Cout object
cout %26lt;%26lt; "Hello world";
//Get keyboard input.
getch();
}
- Void
Reply:You could also open a dos window and run the program from the dos window. Start-%26gt;Run either use cmd or command, depending on your operating system.
I think there is even an option to keep the window resident in the options for the .exe file. Check the properties on your .exe icon.
You could ask for input, then type a key. That will quit the program. Use a for loop while key != 'q'; That is the any key to continue loop.
//This isn't perfect, but it gives you the idea.
char key = 'x';
while (key!= 'q')
{ //do stuff
printf("Press q to quit, any key to continue\n");
getkey(key);
}
You could also make the program wait a while.
I can't exactly remember the statement to make the code wait.
Pause, Wait, delay?
Reply:Call system("PAUSE"); before calling exit or before returning out of the function "main".
Reply:Try these demo tuts. http://www.computer-training-software.co...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment