/** @fn * @brief string转字节流 * @param (IN) unsigned char (&szArray)[N] 输出参数无终止符 * @return */ template inline void String2Bytes(unsigned char (&szArray)[N], const char* pStr)
{
assert(pStr != NULL); // 不能为NULL
memset(szArray, 0, N);
strncpy((char*)szArray, pStr, N);
}
/** @fn * @brief 字节流转string * @param (IN) const unsigned char (&szArray)[N] 输入参数无终止符 * @return */ template inline string Bytes2String(const unsigned char (&szArray)[N])
{ char szDuplicate[N + 1] = { 0 };
memcpy(szDuplicate, szArray, N);
return szDuplicate;
}
网友评论