【发布时间】:2020-08-23 03:56:15
【问题描述】:
考虑以下代码:
void fun (string &str1, string &str2)
{
const char* cstr;
....
if(strlen(cstr = (str1+str2).c_str()) < 15)
{
// here cstr used
}
}
条件本身工作正常,但在 if 条件主体 cstr 中包含垃圾。为什么?
【问题讨论】:
-
可以使用
std::string::length,为什么还要使用strlen?