Question

Hey! I have textBox with text like "12:30" and this code textBox -> Text -> ToString() -> Split(':')[1] It return "30" as string. And I want convert it to Int. How? I founded function like Convert::ToInt32() etc, but it doesnt work for my c++ (Visual C++ 2010 -> Winfow Form). Help me plz! (I started learn c++ 2 days ago)

And i use Managed C++

Was it helpful?

Solution

As you're using Managed C++, then you can do this:

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

Use whatever you need!

OTHER TIPS

you can use c standard lib frunction atoi

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

Edit: Oh, your are using managed C++, then one of the following two should do the job

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

Refer to this page with an example: http://msdn.microsoft.com/en-us/library/b3h1hf19.aspx

I use

int intVar = Int32::Parse(stringVar);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top