views:

171

answers:

3

i need the code to convert the string type data into integer type data if i have entered a numerical value in the text box. i am using visual c++ windows forms and the visual studio

A: 

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;
Naveen
System::String^ txt1 = this->textBox1->Text;System::String^ s = txt1; txt1 = ""; this->textBox1->Text = txt1;my code is as above....i have to convert this string s to integer type
suman
A: 

As long as you can access the raw character data in the text box you can simply use atoi

fbrereto
System::String^ txt1 = this->textBox1->Text; System::String^ s = txt1; txt1 = ""; this->textBox1->Text = txt1; my code is as above....i have to convert this string s to integer type
suman
+2  A: 

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.

OregonGhost
its not working can u give the exact code
suman
`int i = Int32::Parse(myTextBox->Text);` If it still doesn't work, post what *you* already have and describe exactly *what* doesn't work. I don't really know C++/CLI, however, let alone Managed C++.
OregonGhost