•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,333 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,273 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 516 | Replies: 2 | Solved
![]() |
•
•
Join Date: Jan 2008
Posts: 1,747
Reputation:
Rep Power: 8
Solved Threads: 217
I am trying to write a simple "Hello World" to the console. I created an empty C++ project in Visual C++ 2008, and added this one file:
I get this error:
I'm able to use the System namespace when I build a Windows Forms application, but not a console application, regardless of whether I use the precompiled headers. What do I need to do to use the System namespace?
cplusplus Syntax (Toggle Plain Text)
// main.cpp using namespace System; int main () { Console::WriteLine("Hello World"); return 0; }
I get this error:
Error 1 error C2871: 'System' : a namespace with this name does not exist
I'm able to use the System namespace when I build a Windows Forms application, but not a console application, regardless of whether I use the precompiled headers. What do I need to do to use the System namespace?
You need to add the appropriate DLL as a reference. You can do that from the UI by right clicking on your project and choosing "References". From there you can add a new reference for .NET. Alternatively you can reference the DLL directly from your code with a #using statement:
cplusplus Syntax (Toggle Plain Text)
#using <mscorlib.dll> using namespace System; int main() { Console::WriteLine ( "Hello, world!" ); }
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
•
•
Join Date: Jan 2008
Posts: 1,747
Reputation:
Rep Power: 8
Solved Threads: 217
•
•
•
•
You need to add the appropriate DLL as a reference. You can do that from the UI by right clicking on your project and choosing "References". From there you can add a new reference for .NET. Alternatively you can reference the DLL directly from your code with a #using statement:
cplusplus Syntax (Toggle Plain Text)
#using <mscorlib.dll> using namespace System; int main() { Console::WriteLine ( "Hello, world!" ); }
Yep, those both both worked. FYI for anyone who runs into this in the future, if after doing the above, you get an error like this:
Error 1 fatal error C1190: managed targeted code requires a '/clr' option
check Configuration Properties -> General -> Common Language Runtime Support in the project properties and make sure that the following IS NOT the option selected:
No Common Language Runtime support
Thanks Narue!
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
apple command computer console development engine france game games gaming gartner google hardware internet law leopard library linux live microsoft msn news nintendo open operating operating system os parliament patents playstation prompt ps3 registry root search sony source switching system technology torvalds tweaks upgrade vista wii wiimote windows xbox xbox 360 xp
- Previous Thread: Cannot see console output in Visual C++
- Next Thread: panel



Linear Mode