Textbox中的文本从String ^转换为int [英] Text from Textbox covert from String^ to int

查看:219
本文介绍了Textbox中的文本从String ^转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在做一个应用程序,并尝试从一个textBox获取一个值,然后将其转换为整数进一步使用。我有以下代码:

Currently I'm making an application and try to get a value from a textBox and convert it then to an integer for further use. I have the following code:

System::String^ maxTTL = textBoxMaxTTL->Text; 
std::string bla = marshal_as<std::string>(maxTTL); //System string^ to std::string
int maxTTL2 = std::atoi(bla.c_str());

似乎maxTTL2仍然取值为'0'。当我使用 stoi 参数时,它会抛出以下异常:stoi参数超出范围。有人想解决这个问题吗?

It seems that maxTTL2 still got the value of '0'. When I use the stoi argument it throws the following exception: stoi argument out of range. Has somebody an idea to resolve this?

推荐答案

我认为你可以做:

int i = Int32::Parse(maxTTL);

之后,您将获得 i 。您还可以使用try块防弹代码。

Afterwards you will get the int in i. You can also bulletproof the code with a try block.

这篇关于Textbox中的文本从String ^转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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