如何将 System::String 转换为 unsigned char *?
我看到了另一篇文章 建议如下:
String^ clistr = gcnew String("sample");
IntPtr p = Marshal::StringToHGlobalAnsi(clistr);
char *pNewCharStr = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);
我只是想检查一下是否有其他首选方法,或者上述方法是否有问题?
I saw another post that suggested the following:
String^ clistr = gcnew String("sample");
IntPtr p = Marshal::StringToHGlobalAnsi(clistr);
char *pNewCharStr = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);
I just wanted to check and see if there is any other, preferred way, or if anything was wrong with the above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谷歌上的第一个结果“System::String char*”似乎提供了相当全面的指导。
http://support.microsoft.com/kb/311259
The first result on google for "System::String char*" seems to offer pretty comprehensive guidance.
http://support.microsoft.com/kb/311259