使用系统命名空间using namespace System的方法

在我们使用VS2008编程时,可能会用到系统的命名空间,但是在直接使用时经常出现问题,比如:

  using namespace System;

VS2008会报错,说找不到system等名,这是因为vs这里用到了clr,也就是Common Language Runtime,而不般情况下是不用的,在属性里,打开对clr的支持就可以了。

右键单击Solution Explorer中的工程 --->
选择References --->
打开“Propery Pages”页,在左边栏选择Configuration Properties--->Common Language RunTime support ,在下拉菜单里选择

Pure MSIL Common Language Runtime Support (/clr:pure) 即可。

 

另外如果使用到using namespace System::Windows::Forms; 时,还需把对应的.net的引用加入的工程里。

否则可能出现以下提示:

1>.\VCOMTestDlg.cpp(13) : error C3083: 'Windows': the symbol to the left of a '::' must be a type
1>.\VCOMTestDlg.cpp(13) : error C2039: 'Forms' : is not a member of 'System'
1>.\VCOMTestDlg.cpp(13) : error C2871: 'Forms' : a namespace with this name does not exist

 

具体操作步骤如下:

1.右键单击Solution Explorer中的工程 --->选择References --->
打开“Propery Pages”页,在左边栏选择Common Properties的Framework andReferences项.

2.在中间栏的下边点击“Add NewReferences ”按钮,弹出“Add References”对话框 --->选择".NET"页.

3.选择“System.Windows.Forms 版本为 Version 2.0.0.0”项,请点击OK按钮.

返回到“Propery Pages”页,可以看到在“References”栏Name中新增了“System.Windows.Forms”项,点击“Propery Pages”页的OK按钮回到工程。 

重新编译工程即可。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值