locked
Program opens, then closes right away

    Question

  • I have writen this code:

     

    # include <iostream>

    using namespace std;

    int main ()

    {

    cout << "Hello World";

    return 0;

    }

     

    then compiled it, but when I open the executable, it opens then closes right away, and I was told that it's running to fast, is there any line of code that will make a set pause?

    Sunday, December 24, 2006 6:18 PM

Answers

  • actully, it is C++. put "system("pause");" just before the line that says "return 0;"
    Monday, December 25, 2006 1:16 PM

All replies

  •  

    You're in the wrong forum because that's C.

    But the answer to your question is:

    place a read console just before the return.

    Sunday, December 24, 2006 6:25 PM
  • Moved VB Express forum to C++ Express forum.
    Sunday, December 24, 2006 6:35 PM
  • actully, it is C++. put "system("pause");" just before the line that says "return 0;"
    Monday, December 25, 2006 1:16 PM
  • Thankyou sincerley, I have been waiting for that line of code for weeks, you've realy made my day, thanks a million.
    Friday, December 29, 2006 3:04 AM
  • np ;)

     

    remeber, any "return <number>;" (replace <number> with any number) in "int main()" will end the program. if you dont want to display anything at the end do:

    #include <iostream>

    #include <windows.h>

     using namespace std;

    int main()

    {

            cout << "hello world!" << endl;

            while(1) Sleep(100);

            return 0;

    }

    Friday, December 29, 2006 3:11 AM
  • I just tried the code sample you wrote, and the compiler can't find the include file 'windows.h'.
    Sunday, December 31, 2006 10:46 PM
  • you nedd to install the SDK for express edition. and point it to the include directory

    Monday, January 01, 2007 6:53 PM
  • I'm not quite sure where to find the SDK for Visual C++ 2005 Express Edition, could you please give me a URL? thx, and when you say "point it to the include directory" do you mean install the SDK there?
    Tuesday, January 02, 2007 1:04 AM
  • http://www.microsoft.com/downloads/details.aspx?familyid=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=en

     

    1) install it to the default derectory, take a note of this.

    2) when full installed, in Express Edition. go to Tools -> Options -> Projects and Solutions -> VC++ Directorys.

    3)  the defualt of "Executible files" should come up add a new directory and point it to. "<installdir of SDK>\bin"

    4) next go to "Include Files", add a new directory and point it to "<installdir of SDK>\Include"

    5) next, go to "Library files" and make a new directory and point it to "<installdir of SDK>\lib"

     

    and try your program again.

    Tuesday, January 02, 2007 6:43 AM