i_r_slayer Posted August 20, 2009 Share Posted August 20, 2009 Today I mustered the will to bust out my Sams teach yourself C++ book, lets just say I've had less frustrating experiences. After all kinds of wonderful issues due to the C++ compiler (Borland: C++BuilderX) not installing correctly on my computer, I finally got a trial version of the 2009 compiler and dove into the infamous "Hello World!" program. When I compile/link/run this code, the command prompt shows up for a split second then disappears. No errors are found and everything seems to be working correctly. I suspect my problem lies within the act of compiling -> link -> run, but I feel like I'm doing everything correctly. If someone could point out some possible mistakes or has some advice I would appreciate it. Below is the code I used. #include int main() { std::cout << "Hello World!\n"; return 0; } Link to comment Share on other sites More sharing options...
Makoto_the_Phoenix Posted August 20, 2009 Share Posted August 20, 2009 To compile your program with debug information, choose Project|Options, click the Compiler page, and make sure Debug information is checked. Pulled it from the C++ Builder 6 Quick Start guide on this page: http://docs.embarcadero.com/products/rad_studio/ Just for the record, it compiles and runs without errors on g++. Good luck with C++ man. :P Linux User/Enthusiast | Full-Stack Software Engineer | Stack Overflow Member | GIMP User...Alright, the Elf City update lured me back to RS over a year ago. Link to comment Share on other sites More sharing options...
Denismage Posted August 20, 2009 Share Posted August 20, 2009 It's working fine. It quits because it ends outputting hello world and there's to interrupt. This is how you need to do it (snippet from my program) int check() { if( Process( ), Modules( ), Users( ), Registry( ) == 0 ) { printf( "Nothing Detected\n" ); getchar( ); // - This will pause the program until you press any key. ExitProcess(0); return 0; } By the way I use Dev-C++, I recommend you do the same. Link to comment Share on other sites More sharing options...
dsavi Posted August 20, 2009 Share Posted August 20, 2009 DevCpp looks good yeah, as it supports GCC based compilers like MinGW (From what I understand you're on Windows). Link to comment Share on other sites More sharing options...
Sbrideau Posted August 20, 2009 Share Posted August 20, 2009 The reason is simple, you didn't ask the system to pause, so it continues and stops the program after showing the Hello World. The way I did it when I started programming is as follows. #include #include using namespace std; int main () { cout << "Hello World" << endl; _getch(); return 0; } But On windows you have this too: #include using namespace std; int main () { cout << "Hello World" << endl; system("pause"); return 0; } LOL all that just to tell you it's a simple need to stop the program from closing (return 0 tells the execution is finished, in this case, and that's why the program closes right away if you don't put something before that). Link to comment Share on other sites More sharing options...
sheep455_is_the_best Posted August 20, 2009 Share Posted August 20, 2009 From what I've heard using system("pause"); is generally "bad", due to it calling a windows function. It is better to wait for userinput or likewise. [Whip drops: 13] Link to comment Share on other sites More sharing options...
MageUK Posted August 21, 2009 Share Posted August 21, 2009 Run your program from the command prompt rather than just double clicking it. Then you'll see any output without needing to edit the code at all. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now