First look at the explanation of _tcstol on MSDN
1. Different forms on different platformsTCHAR.H Routine | _UNICODE & _MBCS Not Defined | _MBCS Defined | _UNICODE Defined |
_tcstol | strtol | strtol | wcstol |
long strtol( const char *nptr, char **endptr, intbase);
long wcstol( const wchar_t *nptr, wchar_t **endptr, intbase);
Definition: Convert a string type into a numeric form according to different bases.Among them: [in] nptr indicates the string pointer to be scanned
[out] endptr stores the remaining strings that cannot be converted after scanning
[ base ] Indicates the base of the number, the value is: 2, 8, 10, 16. You know the corresponding base
Here I quote one of the rules of string matching in PHP : greedy matching! ! ! That is to say, this function will programmatically match all characters that satisfy the current base and convert them into corresponding numbers ! !
example:
- (1). Convert to binary
- #include"afx.h"
- #include<stdio.h>
- void main()
- {
- char c[5]="0131";
- CString cs=_T(c);
- LPTSTR pstr = NULL;
- int last=_tcstol(c,pstr,2); //2 means binary
- printf( "%d\n" ,last); //Use decimal to output the result as 1
- printf( "%s\n" ,pstr); //Output: 31
- }
Let's take another example
- 2). Convert to octal
- #include"afx.h"
- #include<stdio.h>
- void main()
- {
- char c[7]="010a,!";
- CString cs=_T(c);
- LPTSTR pstr = NULL;
- int last=_tcstol(c,pstr ,8); //8 means octal printf("%d\n",last);//The output result in decimal is 8
- printf( "%s\n" ,pstr); //Output: a,!
- }
Reference article: http://fpcfjf.blog.163.com/blog/static/55469793201015111136406/