Noob question.. ,

Started by
17 comments, last by pulpfist 14 years, 4 months ago
// 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?
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.
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.
How do you "try to run it"?

How does "it fail"?
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?
What do you have against system("pause"); ?
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()
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 >,>
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?
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 ==========

This topic is closed to new replies.

Advertisement