TechSpot

win xp dos?

By scopexmoh
Oct 18, 2003
Topic Status:
Not open for further replies.
  1. hello....i am starting to learn to program in c++ and have a small question...it seems that when i write a simple program, such as the hello world.....i dont have time to see the message when running the program....the dos window pops up and then closes really fast....i also noticed this when tryin to run dos commands from the sys32 folder..is this a result of the dos change in win xp? is there anyway i can get these boxes to not automaticlly close?
  2. Didou

    Didou Bowtie extraordinair! Posts: 5,899

    The reason it closes so fast is because the system opens a command prompt, exectutes the program & exits straight away. If you want to see you programs output, at the end of the intructions, add a getch();.

    That way, the programm will wait for you to hit a key on the keyboard before exiting.

    If you want to launch a command prompt from which to execute your programs, got to Start Menu -> Run -> cmd
  3. scopexmoh

    scopexmoh TS Rookie Topic Starter Posts: 20

    is that at the end of the source code.....? or after the command?? explain please.....thanks for your help!
  4. Didou

    Didou Bowtie extraordinair! Posts: 5,899

    Like this :

    #include "stdafx.h"
    #include "conio.h" //required to use getch()

    int main(int argc, char* argv[])
    {
    printf("Hello World!\n");
    getch(); //this is where you add it
    return 0;
    }


    PS This was done on MSVC 6
  5. scopexmoh

    scopexmoh TS Rookie Topic Starter Posts: 20

    o ok ....well thats a pain......o well.....that was never explained in my c course...any one know of a good up to date online c training or tuts?
Topic Status:
Not open for further replies.


Add New Comment

TechSpot Members
Login or sign up for free,
it takes about 30 seconds.
You may also...


Get complete access to the TechSpot community. Join thousands of technology enthusiasts that contribute and share knowledge in our forum. Get a private inbox, upload your own photo gallery and more.