嘿!我有文本框,带有诸如“ 12:30”和此代码之类的文本框 textBox -> Text -> ToString() -> Split(':')[1] 它返回“ 30”为字符串。我想将其转换为int。如何?我像Convert :: toint32()等创建了功能,但它不适用于我的C ++(Visual C ++ 2010-> WinFow form)。帮我! (我开始学习C ++ 2天前)

我用 管理 C ++

有帮助吗?

解决方案

当您使用托管C ++时,您可以这样做:

double foo = System::Convert::ToDouble("200");
int bar = System::Convert::ToInt32("200");

使用您需要的任何东西!

其他提示

您可以使用c标准lib frunction atoi

CString s = "30";
int x = atoi( s ); // x is now 30

编辑:哦,您使用的是托管C ++,然后以下两个应该完成工作

System::Convert::ToInt32(str, 10);
System::Int32::Parse(str);

请参阅此页面,其中一个示例: http://msdn.microsoft.com/en-us/library/b3h1hf19.aspx

我用

int intVar = Int32::Parse(stringVar);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top