Hello World

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 20
Reputation: DonkeyKong92 is an unknown quantity at this point 
Solved Threads: 1
DonkeyKong92 DonkeyKong92 is offline Offline
Newbie Poster

Hello World

 
0
  #1
Jul 20th, 2008
Hi all, ok i have just started learning C++ today and i have download "Visual C++ 2008 Express Edition" and i am trying to make the "Hello World" program. I clicked on "Create Project" and then "Win32 Console Application" and then typed in the name "Hello World" then i right clicked on "Source Files" then "Add New Item" and then ".cpp" and typed in "Hello World" then i wrote into the big black page...

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main ()
  6. {
  7. cout << "Hello World! ";
  8. cout << "I'm a C++ program";
  9. return 0;
  10. }

And then i clicked on "Build" then "Build Solution" then i clicked the green arrow "Start Debugging"

Then ERROR... The black command prompt screen shows up for about 1 second and disapears before i can even read the writing.

Please help... Thanks for comments
Last edited by DonkeyKong92; Jul 20th, 2008 at 3:25 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Hello World

 
0
  #2
Jul 20th, 2008
you have to add something before the return 0 to make the program stop. like this:
#include <iostream>

using namespace std;

int main ()
{
  cout << "Hello World! ";
  cout << "I'm a C++ program";
  cin.get(); 
  return 0;
}

There are several other ways to do it too -- all of them are correct.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 401
Reputation: CoolGamer48 is on a distinguished road 
Solved Threads: 40
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Pro in Training

Re: Hello World

 
0
  #3
Jul 20th, 2008
If you're on windows, a common way to do it is system("PAUSE"); . It gives a prompt like "Press any key to continue..."
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 20
Reputation: DonkeyKong92 is an unknown quantity at this point 
Solved Threads: 1
DonkeyKong92 DonkeyKong92 is offline Offline
Newbie Poster

Re: Hello World

 
0
  #4
Jul 20th, 2008
This is a good forum Very fast responces and very helpful
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Hello World

 
0
  #5
Jul 20th, 2008
Originally Posted by CoolGamer48 View Post
If you're on windows, a common way to do it is system("PAUSE"); . It gives a prompt like "Press any key to continue..."
Why you should not use that.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 20
Reputation: DonkeyKong92 is an unknown quantity at this point 
Solved Threads: 1
DonkeyKong92 DonkeyKong92 is offline Offline
Newbie Poster

Re: Hello World

 
0
  #6
Jul 20th, 2008
Interesting, thank you for the advice, also i have another question, whenever you make a program in c++ visual 2008 does the program always appear in command prompt?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 401
Reputation: CoolGamer48 is on a distinguished road 
Solved Threads: 40
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Pro in Training

Re: Hello World

 
0
  #7
Jul 20th, 2008
Originally Posted by DonkeyKong92 View Post
Interesting, thank you for the advice, also i have another question, whenever you make a program in c++ visual 2008 does the program always appear in command prompt?
No. Absolutely not. However (not 100% sure about this), I believe any time you have a main() function, a console will open in VC++. I ran this program:
  1. int main()
  2. {
  3. }

and a console window still came up. I'm not sure if there's a way to prevent that. If you use WinMain() and create a window with the Windows API:
  1. #include <windows.h>
  2.  
  3. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR cmdLine,int nShowCmd)
  4. {
  5. }
a console won't come up.
Last edited by CoolGamer48; Jul 20th, 2008 at 9:21 pm.
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 2
Reputation: Kungpao is an unknown quantity at this point 
Solved Threads: 0
Kungpao Kungpao is offline Offline
Newbie Poster

Re: Hello World

 
0
  #8
Jan 4th, 2009
Try putting this inbetween the parenthisis of the 'int main()'

int main(int argc, char*argv[])

and on a line inbetween 'return 0;' and the string, put...

system("PAUSE");

And that should help your problems.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 4
Reputation: aryansmit3754 is an unknown quantity at this point 
Solved Threads: 0
aryansmit3754 aryansmit3754 is offline Offline
Newbie Poster

Re: Hello World

 
0
  #9
Jan 7th, 2009
also use getch();
include<conio.h>
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Hello World

 
0
  #10
Jan 7th, 2009
Originally Posted by Kungpao View Post
Try putting this inbetween the parenthisis of the 'int main()'

int main(int argc, char*argv[])

and on a line inbetween 'return 0;' and the string, put...

system("PAUSE");

And that should help your problems.
Reasons to avoid system("PAUSE");
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC