Jump to content
  • Advertisement
Sign in to follow this  
Mr_Fayce

Noob question.. ,

This topic is 3237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

// Hello planet #include <iostream> using namespace std; int main () { cout << "Hello World!"; return 0; } Whenever I try run this, it fails.. Is something wrong with the coding?

Share this post


Link to post
Share on other sites
Advertisement
It appears to be working fine,

although you may wish to write this line of code instead:

std::cout << "Hello World!"<<std::endl;

this just ensures that Hello World! is printed on a line separate from your terminal/cmd call line.

If it's still not working, check out how you are compiling the program.

Share this post


Link to post
Share on other sites
I don't think it fails, it just does it so fast that it just opens up and shuts down.

you might want something like this:

// Hello planet

#include <iostream>
using namespace std;

int main ()
{
cout << "Hello World!";

system("PAUSE");

return 0;
}

though I suggest you avoid using system("Pause") when ur programming for real because it takes a lot of memory or something. cin.get() would probably work better.

Share this post


Link to post
Share on other sites
Yea that works fine. If you do the whole std::cout and std::endl then you won't need the line of code "using namespace std;"

I wouldn't use system("PAUSE")though.

Try using cin instead or if in visual studio you can do "Start without Debugging" under Debug. That should work (Just make sure it builds okay though)

As for failing, what are the errors? Or what happens?

Share this post


Link to post
Share on other sites
I believe its cuz system("PAUSE"); is not very effecient in terms of speed and memory speed.

http://www.gidnetwork.com/b-61.html

it's a link describing why you should avoid it and alternate methods such as cin.get()

Share this post


Link to post
Share on other sites
Hmm, I thought the code was correct.

After trying to run at the bottom it says

"========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========="

And nothing happens >,>

Share this post


Link to post
Share on other sites
Quote:
Original post by Mr_Fayce
Hmm, I thought the code was correct.

After trying to run at the bottom it says

"========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========="

And nothing happens >,>
And what does it say above that? Why is it failing to build?

Share this post


Link to post
Share on other sites
Copy and pasted;

1>------ Build started: Project: fdsgafdg, Configuration: Debug Win32 ------
1>Compiling...
1>fdsgafdg.cpp
1>c:\users\mr_fayce\documents\visual studio 2008\projects\fdsgafdg\fdsgafdg\fdsgafdg.cpp(4) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\mr_fayce\documents\visual studio 2008\projects\fdsgafdg\fdsgafdg\fdsgafdg.cpp(15) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>Build log was saved at "file://c:\Users\Mr_Fayce\Documents\Visual Studio 2008\Projects\fdsgafdg\fdsgafdg\Debug\BuildLog.htm"
1>fdsgafdg - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!