English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

2007-01-21 05:23:14 · 5 answers · asked by mark 1 in Computers & Internet Programming & Design

5 answers

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.

2007-01-22 01:18:57 · answer #1 · answered by justme 7 · 0 0

You could also open a dos window and run the program from the dos window. Start->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?

2007-01-21 13:45:26 · answer #2 · answered by Anonymous · 0 0

Answer to your other post about this problem.
Here is the code again.....

//Pre-Processor directives
#include
#include // for getch();

//Specified namespace
using namespace std;

int main()
{
//Cout object
cout << "Hello world";

//Get keyboard input.
getch();
}





- Void

2007-01-22 21:05:15 · answer #3 · answered by Hex 5 · 0 0

Call system("PAUSE"); before calling exit or before returning out of the function "main".

2007-01-21 14:16:52 · answer #4 · answered by Fox 3 · 0 0

Try these demo tuts. http://www.computer-training-software.com/c.htm

2007-01-21 13:31:03 · answer #5 · answered by Anonymous · 0 0

fedest.com, questions and answers