Beginner Program Assistance

Im attempting the Hello World program, but it always gets the build errors menu, even when i copy a correct version from the internet. Here is the one i am currently trying:

// Hello World, by Omegas Squared

// Include the iostream library
#include <iostream>

// Use the standard namespace
using namespace std;

void main ( )
{
// Print text to the screen
cout << "Hello world!" <<endl;
}

If someone could please help me out that would be great
What are the errors? Your program looks fine, except according to the standard you ought to have int main() and a return 0;
A box pops up saying "There were build errors. Would you like to continue and run the last succesful build?"
Depends on compiler. Example, following code works well in Dev c++.

1
2
3
4
5
6
7
#include <iostream>
using namespace std;
main ( )
{
 // Print text to the screen
cout << "Hello world!" <<endl;
}


im using microsoft visual c++ 2008
I think you mean the IDE, yes, Dev-C++ lets you compile a single *.cpp without making a project.
Not sure about VC++...

[EDITED]
oh but why...main has to return int, at least something other than this is not standard...

[EDITED]
Some compilers let you declare main() to return void, but working doesn't mean it's a good habit.

[EDITED]
lol. Return 0 is returning nothing? 0 is an int, not void.
Last edited on
1
2
3
4
5
6
7
8
#include <iostream>

using namespace std;

void main()
{
cout << "Hello World!" << endl;
}


I just made this one in visual, and it worked. What file are you writing? A .cpp file?

@Zhuge: return 0 is only needed when not using void.
@Wmheric: You can compile a single .cpp file in VC++. Also, you have to use return 0. That makes it return nothing. and thus has the same effect as void.
Last edited on
Topic archived. No new replies allowed.