Kyle McK

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



Re: Visual C++ Express Edition Program opens, then closes right away

ReneeC

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.






Re: Visual C++ Express Edition Program opens, then closes right away

Peter Ritchie

Moved VB Express forum to C++ Express forum.




Re: Visual C++ Express Edition Program opens, then closes right away

help-linux

actully, it is C++. put "system("pause");" just before the line that says "return 0;"




Re: Visual C++ Express Edition Program opens, then closes right away

Kyle McK

Thankyou sincerley, I have been waiting for that line of code for weeks, you've realy made my day, thanks a million.



Re: Visual C++ Express Edition Program opens, then closes right away

help-linux

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;

}






Re: Visual C++ Express Edition Program opens, then closes right away

Kyle McK

I just tried the code sample you wrote, and the compiler can't find the include file 'windows.h'.



Re: Visual C++ Express Edition Program opens, then closes right away

help-linux

you nedd to install the SDK for express edition. and point it to the include directory






Re: Visual C++ Express Edition Program opens, then closes right away

Kyle McK

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



Re: Visual C++ Express Edition Program opens, then closes right away

help-linux

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.