如何在 vc++ 中将“System::String ^”转换为“const char *”?
My code:
String ^Result1= "C:/Users/Dev/Desktop/imag.jpg";
IplImage *img1 = cvLoadImage(Result1, 1);
如果我确实像上面那样,它会生成以下错误。
error C2664: 'cvLoadImage' : cannot convert parameter 1 from 'System::String ^' to 'const char *'
请帮我。
就像这样:如何在 Visual C++ 中从 System::String* 转换为 Char* http://support.microsoft.com/kb/311259
System::String ^ str = "Hello world\n";
//method 1
pin_ptr<const wchar_t> str1 = PtrToStringChars(str);
wprintf(str1);
//method 2
char* str2 = (char*)Marshal::StringToHGlobalAnsi(str).ToPointer();
printf(str2);
Marshal::FreeHGlobal((IntPtr)str2);
//method 3
CString str3(str);
wprintf(str3);
//method 4
#if _MSC_VER > 1499 // Visual C++ 2008 only
marshal_context ^ context = gcnew marshal_context();
const char* str4 = context->marshal_as<const char*>(str);
puts(str4);
delete context;
#endif
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)