您的位置:首页 > 编程语言 > C语言/C++

HOW TO:在 Visual C++ .NET 中从 System::String* 转换为 Char*

2010-08-05 10:35 387 查看
本文介绍使用 Visual C++ .NET 中的托管扩展从 System::String* 转换为 char* 的若干方法。

代码

public void ConvertStringFloat(string stringVal) {
float floatVal = 0;

try {
floatVal = System.Convert.ToSingle(stringVal);
System.Console.WriteLine(
"The string as a float is {0}.", floatVal);
}
catch (System.OverflowException){
System.Console.WriteLine(
"The conversion from string-to-float overflowed.");
}
catch (System.FormatException) {
System.Console.WriteLine(
"The string is not formatted as a float.");
}
catch (System.ArgumentNullException) {
System.Console.WriteLine(
"The string is null.");
}

// Float to string conversion will not overflow.
stringVal = System.Convert.ToString(floatVal);
System.Console.WriteLine(
"The float as a string is {0}.", stringVal);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: