User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jan 2008
Posts: 1,747
Reputation: VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice 
Rep Power: 8
Solved Threads: 217
VernonDozier VernonDozier is offline Offline
Posting Virtuoso

using namespace System in Vis. C++ Console App

  #1  
May 22nd, 2008
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:

  1. // main.cpp
  2.  
  3. using namespace System;
  4.  
  5. int main ()
  6. {
  7. Console::WriteLine("Hello World");
  8. return 0;
  9. }

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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,300
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 455
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: using namespace System in Vis. C++ Console App

  #2  
May 22nd, 2008
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:
  1. #using <mscorlib.dll>
  2.  
  3. using namespace System;
  4.  
  5. int main()
  6. {
  7. Console::WriteLine ( "Hello, world!" );
  8. }
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Jan 2008
Posts: 1,747
Reputation: VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice 
Rep Power: 8
Solved Threads: 217
VernonDozier VernonDozier is offline Offline
Posting Virtuoso

Re: using namespace System in Vis. C++ Console App

  #3  
May 22nd, 2008
Originally Posted by Narue View Post
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:
  1. #using <mscorlib.dll>
  2.  
  3. using namespace System;
  4.  
  5. int main()
  6. {
  7. Console::WriteLine ( "Hello, world!" );
  8. }


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
If it is, change it to one of the options that has "/clr" in it. All of them worked for me, though one is deprecated. After making that change, the program worked.

Thanks Narue!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC