如果我的 C++ 代码(如下所示)有一个初始化为空字符串的字符串,这有什么关系:
std::string myStr = "";
....some code to optionally populate 'myStr'...
if (myStr != "") {
// do something
}
与无/空初始化:
std::string myStr;
....some code to optionally populate 'myStr'...
if (myStr != NULL) {
// do something
}
是否有任何最佳实践或陷阱?