Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using namespace System; in Visual Studio 2013

I am trying to use the Console::SetCursorPosition(int, int) method. When I add the line using namespace System;, as shown in the C++ example from the preceding MSDN documentation, I get the error "Error: name must be a namespace name". I have been trying stuff for a couple hours now, but frustratingly without success. I have come across a ton of documentation for Visual Studio 2010 and 2012, but very little for 2013. The closest I have come is Lib Files as Linker Input. Steps 1-3 are easy enough, but step 4 is not clear to me: "Modify the Additional Dependencies property.". Looking at what is already there, it seems like I can just add a .lib file. But I don't have a System.lib.

So frustrated, so confused.

How can I use the System namespace in Visual Studio 2013 Update 4 for C++?

like image 660
Evorlor Avatar asked Dec 19 '22 06:12

Evorlor


2 Answers

To formalize and expand on my comment, the Console class and generally the System namespace are part of the .NET framework.

In that context, the "C++" tab included in the MSDN documentation page of the Console::SetCursorPosition(int, int) method actually refers to the C++/CLI language. The C++/CLI language is distinct (although intentionally similar) from the C++ language. Correspondingly, the C++/CLI language contains various constructs which are not recognized by the C++ compiler toolset used when compiling Win32 projects.

In other words, to get rid of the "Error: name must be a namespace name" error, you would need to convert your Win32 C++ project to a CLR project. The easiest way to do that would be to create a new project, selecting one of the templates under "Visual C++" / "CLR":

Creating new C++ CLR project

The equivalent of .lib file depdendencies (relative to your Lib Files as Linker Input link) of Win32 projects for CLR project would be assembly references. You'd then typically add those assembly references with "Add References" under "Common Properties , References" project properties:

CLR assembly references

However, in your specific case you may very well find out that the System assembly reference is already included as part of the CLR project template. You may want to check How to: Add or Remove References on MSDN for more details.

Finally, if you absolutely want to manually convert an existing Win32 project, you would need to set the "Common Language Runtime Support" project properties under "General" and the "C/C++ , General" tabs to one of /clr, /clr:pure, /clr:safe or /clr:oldSyntax (depending on your specific application requirements; if you're just toying around you might want to start with /clr) for all Configurations and Platforms as well as specify the targeted .Net framework version by directly editing the .vcxproj (as indicated in this answer). You would also still need to add assembly dependencies as with the new project approach above.

like image 193
SleuthEye Avatar answered Jan 07 '23 03:01

SleuthEye


You have to set Common Language Runtime Support (/clr) in Configuration Properties - General:

enter image description here

And in Configuration Properties - C/C++ - General:

enter image description here

like image 20
Saullo G. P. Castro Avatar answered Jan 07 '23 01:01

Saullo G. P. Castro