64,642
社区成员
发帖
与我相关
我的任务
分享
#include <afxdisp.h>
#include <windows.h>
#include <stdio.h>
int main() {
CString cs;
ULONG ul;
cs="123";
if (1==sscanf(cs,"%lu",&ul)) {
printf("CString [%s] to ULONG is [%lu]\n",cs,ul);
} else {
printf("CString [%s] to ULONG fail!\n",cs);
}
cs="abc";
if (1==sscanf(cs,"%lu",&ul)) {
printf("CString [%s] to ULONG is [%lu]\n",cs,ul);
} else {
printf("CString [%s] to ULONG fail!\n",cs);
}
return 0;
}
//CString [123] to ULONG is [123]
//CString [abc] to ULONG fail!
//
#ifdef _UNICODE
(PUSHORT)CString1
#else
(PUCHAR)CString1
#endif
//或者干脆
(LPCTSTR)CString1
(PUCHAR)CString1
CString::operator LPCTSTR
operator LPCTSTR ( ) const;
Return Value
A character pointer to the string’s data.
Remarks
This useful casting operator provides an efficient method to access the null-terminated C string contained in a CString object. No characters are copied; only a pointer is returned. Be careful with this operator. If you change a CString object after you have obtained the character pointer, you may cause a reallocation of memory that invalidates the pointer.
CString Overview | Class Members | Hierarchy Chart