Duplicate strings.
char *_strdup( const char *strSource ); wchar_t *_wcsdup( const wchar_t *strSource ); unsigned char *_mbsdup( const unsigned char *strSource ); |
Parameters
Return
Value
Each of these functions returns a pointer to the storage location for the copied string or NULL if storage cannot be allocated.
The _strdup
function calls malloc to allocate storage space for a copy of strSource and
then copies strSource to the allocated space.
就是分配目的串内存空间,然后将源字符串的内容copy
到目的串中。(加一句,用完以后记得要free
掉目的串的内存)
看看这个MSDN
的例子就懂了:
是分配字符串lpszAppName
长度的内存,
然后返回地址指针复制给m_pszAppName
相当于
是分配字符串lpszAppName
长度的内存,
然后返回地址指针赋值给m_pszAppName
相当于