C ++中托管类型和非托管类型之间的转换? [英] Conversion between managed and unmanaged types in C++?

查看:188
本文介绍了C ++中托管类型和非托管类型之间的转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在C ++中使用GUI时,文本字段存储为托管字符串,我想。我需要一种方式将它们转换为标准int,浮动和字符串。任何帮助?

When I use a GUI in C++ the text fields are stored as managed strings, i think. I need a way to convert them to standard ints, floats and strings. Any help?

推荐答案

您可以使用 Marshal.StringToHGlobalAnsi 。确保您在完成后释放它,请致电 Marshal.FreeHGlobal 。要将字符串转换为数字值,可以使用常规的.NET解析函数,如 Int32.Parse

You can convert a System.String into an unmanaged char * using Marshal.StringToHGlobalAnsi. Make sure you free it when you're done by calling Marshal.FreeHGlobal. To convert the strings to numeric values, you can use the regular .NET parsing functions such as Int32.Parse.

这篇关于C ++中托管类型和非托管类型之间的转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆