I try to use _tcstoul for string to unsigned long conversion.
However, it doesn't treat -ve string input as invalid input. Is there any workaround for this? Or I had missed out something?
#include <cstdio>
#include <tchar.h>
int main() {
{
unsigned long iResult(0);
TCHAR *pszStopString;
iResult = _tcstoul(_T("2abc"), &pszStopString, 10);
if( _tcsicmp(pszStopString, _T("")) != 0 ) {
// OK. We reach here.
printf("2abc : Error occur during conversion!\n");
}
}
{
unsigned long iResult(0);
TCHAR *pszStopString;
// iResult = 4294967274
iResult = _tcstoul(_T("-22"), &pszStopString, 10);
if( _tcsicmp(pszStopString, _T("")) != 0 ) {
// Nope. We didn't reach here!
printf("-22 : Error occur during conversion!\n");
}
}
getchar();
}
I expect during conversion of "-22", error shouldn't occur, as "-22" is a negative value, and I am expecting non-negative value returned from _tcstoul.