Jump to content

Just started learning C++


i_r_slayer

Recommended Posts

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;

}

yuki2d.png

Link to comment
Share on other sites

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
s1L0U.jpg
...Alright, the Elf City update lured me back to RS over a year ago.

Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.