August 20, 200916 yr 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; }
August 20, 200916 yr 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.
August 20, 200916 yr 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.
August 20, 200916 yr DevCpp looks good yeah, as it supports GCC based compilers like MinGW (From what I understand you're on Windows).
August 20, 200916 yr 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).
August 20, 200916 yr 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]
August 21, 200916 yr 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.
Create an account or sign in to comment