문제

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++

도움이 되었습니까?

해결책

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!

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top