1、通过判断它的第一个字符是否为空(推荐用这种:原因是判断速度更快)
char* p = "123456"; if(p != nullptr && p[0] == '\0') { //为空 } else if(p == nullptr) { } else { //不为空 }
2、通过判断指针或数组的长度
const char* p = "123456";
if(p != nullptr && strlen(p) == 0)
{
//为空
}
else if(p == nullptr)
{
}
else
{
//不为空
}