943,901 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1776
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 20th, 2008
0

Hello World

Expand Post »
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...

C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
DonkeyKong92 is offline Offline
20 posts
since Jul 2008
Jul 20th, 2008
0

Re: Hello World

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Jul 20th, 2008
0

Re: Hello World

If you're on windows, a common way to do it is system("PAUSE"); . It gives a prompt like "Press any key to continue..."
Reputation Points: 77
Solved Threads: 40
Posting Pro in Training
CoolGamer48 is offline Offline
401 posts
since Jan 2008
Jul 20th, 2008
0

Re: Hello World

This is a good forum Very fast responces and very helpful
Reputation Points: 10
Solved Threads: 1
Newbie Poster
DonkeyKong92 is offline Offline
20 posts
since Jul 2008
Jul 20th, 2008
0

Re: Hello World

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Jul 20th, 2008
0

Re: Hello World

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?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
DonkeyKong92 is offline Offline
20 posts
since Jul 2008
Jul 20th, 2008
0

Re: Hello World

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:
C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 77
Solved Threads: 40
Posting Pro in Training
CoolGamer48 is offline Offline
401 posts
since Jan 2008
Jan 4th, 2009
0

Re: Hello World

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kungpao is offline Offline
2 posts
since Jan 2009
Jan 7th, 2009
0

Re: Hello World

also use getch();
include<conio.h>
Reputation Points: 9
Solved Threads: 0
Newbie Poster
aryansmit3754 is offline Offline
4 posts
since Jan 2009
Jan 7th, 2009
0

Re: Hello World

Click to Expand / Collapse  Quote originally posted by Kungpao ...
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");
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: HELP!!!: Seekp() & Tellg() Problem in C++
Next Thread in C++ Forum Timeline: What do you think?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC