std::string ConvertToString(System::String^ str)
{
int q=(int)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);
char* p=(char*)q;
return std::string(p);
}
String^ str = gcnew String(s.c_str());
简单的System::String和std::string的转换
{
int q=(int)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);
char* p=(char*)q;
return std::string(p);
}
String^ str = gcnew String(s.c_str());
简单的System::String和std::string的转换
本文介绍了一种实现C++标准库中的std::string与.NET Framework中的System::String相互转换的方法。通过使用System::Runtime::InteropServices::Marshal命名空间下的StringToHGlobalAnsi函数完成.NET字符串到C++字符串的转换,反之则通过gcnew操作符实现。
4258

被折叠的 条评论
为什么被折叠?



