Question

Hey! Je textBox avec du texte comme « 12:30 » et ce code textBox -> Text -> ToString() -> Split(':')[1] Il retourne « 30 » sous forme de chaîne. Et je veux le convertir en Int. Comment? J'ai créé la fonction comme Convert :: ToInt32 () etc, mais cela ne fonctionne pas pour mon c ++ (Visual C ++ 2010 -> Winfow Form). Aidez-moi plz! (J'ai commencé à apprendre c ++ il y a 2 jours)

Et j'utilise Gestion C ++

Était-ce utile?

La solution

Comme vous utilisez C ++ managé, vous pouvez faire ceci:

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

Utilisez ce que vous avez besoin!

Autres conseils

vous pouvez utiliser c lib norme frunction atoi

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

Edit: Oh, que vous utilisez gérés C ++, puis l'un des deux suivants devraient faire le travail

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

Reportez-vous à cette page par un exemple: http://msdn.microsoft. com / fr-fr / bibliothèque / b3h1hf19.aspx

J'utilise

int intVar = Int32::Parse(stringVar);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top