string to integer type conversion if the string is taken from text box in visual c++ using visual studion n windows forms
i need the code to convert the string type data into integer type d开发者_如何学Cata if i have entered a numerical value in the text box. i am using visual c++ windows forms and the visual studio
i am using visual c++ windows forms and the visual studio
If it's really Windows Forms (i.e. C++/CLI) it's just Int32::Parse
or Int32::TryParse
, just like in any other .NET language.
I think what he wanted was:
String^ numberS = "42";
int number;
number = Convert::ToInt32(numberS);
Assuming that you have the variable in a std::string
instance, you can use streams to do it like this:
std::string str = "1";
std::istringstream iss;
iss.str(str);
int val = 0;
iss>>val;
As long as you can access the raw character data in the text box you can simply use atoi
精彩评论