Incredibly frustrating. Can't run simple Hello World project

I've copied and pasted a simple Hello World "program", however it will not run, due to some error(s) apparently associated with the line "#include <iostream>". The program is shown below:

#pragma once

using namespace System;

namespace Helloworld {

#include <iostream>

using namespace std;

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

Obviously all I'm trying to do is print "Hello World" to the screen. Instead, I get over 100 errors, the first few of which look like this:

c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244): error C3083: 'vc_attributes': the symbol to the left of a '::' must be a type
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244): error C2039: 'YesNoMaybe' : is not a member of '`global namespace''
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244): error C2146: syntax error : missing ';' before identifier 'SA_YesNoMaybe'
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C3083: 'vc_attributes': the symbol to the left of a '::' must be a type
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C2039: 'YesNoMaybe' : is not a member of '`global namespace''
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C2146: syntax error : missing ';' before identifier 'SA_Yes'
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C2377: 'Helloworld::YesNoMaybe' : redefinition; typedef cannot be overloaded with any other symbol
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244) : see declaration of 'Helloworld::YesNoMaybe'
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C3083: 'vc_attributes': the symbol to the left of a '::' must be a type
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C2039: 'Yes' : is not a member of '`global namespace''
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C2065: 'Yes' : undeclared identifier
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(246): error C3083: 'vc_attributes': the symbol to the left of a '::' must be a type
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(246): error C2039: 'YesNoMaybe' : is not a member of '`global namespace''
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(246): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(246): error C2146: syntax error : missing ';' before identifier 'SA_No'
c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(246): error C2086: 'const int Helloworld::YesNoMaybe' : redefinition

What exactly is going on here? I'm using Visual Basic 2010, if it is relevant.
That namespace Helloworld bugs me, and I think that's the source of all your errors (EDIT: I get 332 using GCC 4.2.1 with all the code except the using namespace System;, but not one after I remove the namespace and all the code that was above its declaration). See if this program works:
1
2
3
4
5
6
7
8
9
#include <iostream>

using namespace std;

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


-And call me in the morning... ahem... Albatross.

P.S.- Visual BASIC 2010 is something different than what you're using. You meant to say Visual Studio 2010, or to be more specific, Visual C++ 2010.

P.P.S.- Please desist from any further learning from that source you were using.
Last edited on
Well, I'm no longer getting over 100 error messages with your code, but I'm instead getting the following message:

Unable to start program 'c:\users\jonathan\documents\visual studio 2010\Projects\HelloWorld\Debug\HelloWorld.dll'
Dumb question, but... what project did you use when creating this? #pragma once and namespaces are more useful for libraries, which seems to be what this was intended to be, and .dll is short for Dynamic Linked Library.

-Albatross
I used a Class Library. Should I be using a blank project or console application instead?
Yes, you should.

-Albatross
when it links it looks for a main function.

because of the namespace yours is called System::main

this works ;-)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
namespace fish {
int main(void) {

    cout << "oi\n";
    return 0;
}
}

int main(int argc, char ** argv) {

    fish::main();
    return 0;
}
Last edited on
Perhaps Visual C++ is too ambitious for an absolute beginner? I used Dev-C++ when I first started. http://sourceforge.net/projects/dev-cpp/

I don't know though; maybe a resident expert can chime in.
Dev-C++ hasn't updated since January of 2008 the last time I checked (the last binary is from 2005!!!), and I recommend not using it simply because of its age (2 years is a long time in computer years; compilers have since improved dramatically). If anything, try wxDev-C++.

Visual Studio is a good set of tools once you know what to click and when (when in doubt, try an empty project), and I started programming using that. If you paid for it, stick with it, else, it's safe to switch to something with fewer confusing options (they can get confusing).

I've heard good things about Code::Blocks + GCC, but I cannot stand up for it as I've never used it.

I myself use Netbeans + GCC, and recommend the combo for people at all skill levels.

-Albatross
Last edited on
Dev-C++ does have a few quirks that are annoying. To be honest, I haven't really used any IDE besides Visual Studio and Dev-C++. I'll have to check out Netbeans. Maybe that will convince me to try learning Java. ;)
Topic archived. No new replies allowed.