Results 1 to 5 of 5

Thread: Program unlaods???

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    47

    Program unlaods???

    Hi,
    I'm currently learning C++ and I copied one simplest program from the book to my compiler, and then I compiled it.
    #incude<iostream.h>
    int main()
    {
    cout << "Hello World \n";
    return 0;
    }

    After I ran the program, I noticed that it loads and automatically unlaods. How do I make it load, stay loads, and when I press the "x" button in the right hand corner, it will unlaod?
    Thanks

  2. #2
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Code:
    #incude <iostream.h>
    #include <stdio.h>
    int main()
    {
    cout << "Hello World \n";
    system("pause");
    return 0;
    }
    This will pause the program until you press a key (oddly enough it says "Press any key to continue...").
    Alcohol & calculus don't mix.
    Never drink & derive.

  3. #3
    Member
    Join Date
    Feb 2001
    Posts
    57
    There better ways to do this but this will work...
    Code:
    #include <iostream.h> 
    int main() 
    { 
    char nothing=0;
    cout << "Hello World \n"; 
    cin >> nothing;
    return 0; 
    }
    just hit any key on the keyboard and then enter to exit.


    chilibean

  4. #4
    Member
    Join Date
    Feb 2001
    Posts
    57

    Sorry Wynd!

    That's the type of code I was thinking of and you beat me to it.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If it's in a console window you shouldn't use the X button to close it, because that can prevent it from cleaning up after itself (the compiler adds a lot more after your main() function has finished).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width