Convert strings to a long-integer value.
___ long strtol( const char *nptr, char **endptr, int base );
nptr: Null-terminated string to convert
endptr: Pointer to character that stops scan //___good way to separate number and alphabet
base: Number base to use
return value: On success, the function returns the converted integral number as a long int
value.
If no valid conversion could be performed, a zero value is returned (0L
).
If the value read is out of the range of representable values by a long int
, the function returns LONG_MAX or LONG_MIN(defined in <climits>), and errno is set to ERANGE.
___ long atol( const char *str );// compared to above one,less powerful,and less safer
___ char * itoa ( int value, char * str, int base );
base: umerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16hexadecimal, 8 octal, and 2 binary.
1.CString和string的转化
CStringcstr(str.c_str());//或者CString cstr(str.data());初始化时才行
cstr=str.c_str();或者cstr=str.data();
str=cstr.GetBuffer(0); //CString -> string
cstr.format("%s", str.c_str()); //string->CString
cstr.format("%s", str.data()); //string->CString
str = LPCSTR(cstr); //CString->string
/*c_str()和data()区别是:前者返回带'/0'的字符串,后者则返回不带'/0'的字符串*/
CStringstr;
str.format("%d",i);//int->CString 其他的基本类型转化类似
i=atoi(str);//CString->int 还有(atof,atol)
char* ptemp=cstr.getbuffer(0);
char* str;
strcpy(str,ptemp);//CString->char*
cstr.releasebuffer(-1);
char*str="lovesha";
CStringcstr=str;//char*->CString string类型不能直接赋值给CString