System::String 转 std下的string

zh2208 2009-02-05 02:30:45
System::String 转 std下的string
String* str = "dd";
string str2 = "";
如何把str中的"dd"赋值到str2中??
...全文
352 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
WestWindSmile 2012-02-29
  • 打赏
  • 举报
回复
真是感谢!帮我一大忙!

[Quote=引用 2 楼 biweilun 的回复:]
C/C++ code

std::string ConvertToString(System::String^ str)
{
int q=(int)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);
char* p=(char*)q;
return std::string(p);
}
[/Quote]
biweilun 2009-02-06
  • 打赏
  • 举报
回复

std::string ConvertToString(System::String^ str)
{
int q=(int)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);
char* p=(char*)q;
return std::string(p);
}
真相重于对错 2009-02-05
  • 打赏
  • 举报
回复
String* str = "dd";
string str2 = reinterpret_cast<char*>(System::Runtime::InteropServices::Marshal::StringToCoTaskMemAnsi(str).ToPointer());

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧