首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VC >

创建什么项目才能 运行using namespace System;解决办法

2012-02-19 
创建什么项目才能 运行using namespace System我在学习一段 如何将System.String转换为std.string 的代码

创建什么项目才能 运行using namespace System;


我在学习一段 如何将System.String转换为std.string 的代码。在vs2008 C++控制台下无法运行一下代码
请问如何建这样的项目工程???

#include <string>
#include <iostream>
using namespace std;
using namespace System;



void MarshalString ( String ^ s, string& os ) {
  using namespace Runtime::InteropServices;
  const char* chars = 
  (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
  os = chars;
  Marshal::FreeHGlobal(IntPtr((void*)chars));
}

void MarshalString ( String ^ s, wstring& os ) {
using namespace Runtime::InteropServices;
  const wchar_t* chars = 
  (const wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer();
  os = chars;
  Marshal::FreeHGlobal(IntPtr((void*)chars));
}

int main() {
  string a = "test";
  wstring b = L"test2";
  String ^ c = gcnew String("abcd");

  cout << a << endl;
  MarshalString(c, a);
  c = "efgh";
  MarshalString(c, b);
  cout << a << endl;
  wcout << b << endl;
}



[解决办法]
c++直接
using namespace std;
[解决办法]
必须使用CLR。

c++跑.net里混不容易啊,容易被挤掉。
[解决办法]

探讨
必须使用CLR。
怎么使用??可否说一下操作过程

[解决办法]
项目类型要选择CLR空项目,代码本人调试通过。

热点排行