简体   繁体   中英

Converting CString to unsigned long

I am trying to convert a string to unsigned long. Here is the code

lCardNum = wcstoul(sCardNo.GetBuffer(sCardNo.GetLength()), NULL,0);

My sCardNo(CString) value is 4294967359. Why do I get lCardNum(unsigned long) as 4294967295 ?

Assuming that your unsigned long integer is 32-bits wide, then you are overflowing it. 0xFFFFFFFF is 4294967295. Your wanted 4294967359 is 0x10000003F, ie , it needs 33 bits.

Go for unsigned long long or __int64 on a Windows box, lookup _wcstoui64 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM