AfxIsValidString
使用這個函式來判斷字串的指標是否有效。
BOOL AfxIsValidString(
LPCSTR lpsz,
int nLength = -1
);
參數
lpsz
要測試的指標nLength
指定測試的字串的長度,以位元組為單位。 值為 1 表示字串將 null 結尾。
傳回值
在偵錯組建中,非零,則為指定大小的字串中指定的索引點;否則為 0。
如果 lpsz 不是空的,請在非偵錯組建,非零;否則為 0。
範例
// Create a character string which should be valid.
char str[12] = "hello world";
// Create a null pointer, which should be an invalid string.
char* null = (char*)0x0;
ASSERT(AfxIsValidString(str, 12));
ASSERT(!AfxIsValidString(null, 5));
需求
標頭: afx.h