Converting a Text into an Integer
-
Hi, I'm in need of a conversion routine to convert a string into a integer(long). I'm relying on CRT function _tcstol to do this. Below shown is my approach: main() { _TCHAR *q = 0; char txt[] = "5x"; long l = _tcstol(txt, &q, 10); if (q && _tcsclen(q)) { cout<<"Invalid Integer"; } } I'm relying on parameter2 in _tcstol to validate a integer. (i.e)the endptr Pointer to character that stops scan. Will this approach work fine in all cases? Thanks in Advance :rose: Rane
-
Hi, I'm in need of a conversion routine to convert a string into a integer(long). I'm relying on CRT function _tcstol to do this. Below shown is my approach: main() { _TCHAR *q = 0; char txt[] = "5x"; long l = _tcstol(txt, &q, 10); if (q && _tcsclen(q)) { cout<<"Invalid Integer"; } } I'm relying on parameter2 in _tcstol to validate a integer. (i.e)the endptr Pointer to character that stops scan. Will this approach work fine in all cases? Thanks in Advance :rose: Rane
Hello, yes, I would do the same as you did for converting a string to an integer. By the way, have you looked at this thread[^]? Best regards, Mihai Moga