Tuesday, July 14, 2009

I need help with my c++ compiler...?

i am using dev-c++4 as my compiler and i put this in





// my first program in C++





#include %26lt;iostream%26gt;


using namespace std;





int main ()


{


cout %26lt;%26lt; "Hello World!";


return 0;


}





then i compile it and it says i have no errors. so i push execute and nothing happens. wat am i doing wrong?

I need help with my c++ compiler...?
First, make sure you clicked both compile and build (you can also just click build directly).





Run your program from the command line. If you don’t want to, you can put in a (acceptable for beginners only) kludge by adding cin.get() to the end of main. See Google for the problem of C++ program closing too quickly.





Finally, I want to correct a technical error in your choice of words. But it’s critical you learn to make this distinction. Dev-C++ is what is known as an IDE. It is not a compiler itself. Your compiler is MingW (that’s what Dev-C++ is designed to use). MingW is the windows port of the gcc compiler. Knowing these details will help you with your Googling efforts.
Reply:....


cout %26lt;%26lt; "Hello World!";


cin.get();


....
Reply:Your program did work, it outputs Hello World but it was so fast you couldn't see it. Youre next line after the cout line should be a cin statement. The screen will pause for the cin, and you will see your Hello World. Then when you hit enter, the program will finish executing and exit. Without a line to pause the program (cin), the program executes, displays hello world, finishes executing and closes, fast enough where you didn't think anything happened.
Reply:You're program should compile fine, no errors. Did you start a console project, if so, you should use command line or dos box if on windows to run it.





Take a look on http://www.nextdawn.nl for a great series of C and C++ tutorials (they also explain compiling).

lady palm

No comments:

Post a Comment