【发布时间】:2010-10-22 07:07:58
【问题描述】:
我的项目有将 NULL 指针视为空字符串的遗留库。
但是当我像这样从 std::wstring 获取返回数据时,
std::wstring strData;
const wchar* pStr = strData.c_str();
ASSERT(NULL == pStr); // ASSERT!!
pStr 不是 NULL 而是 wstring 指向的指针。
当 std::string 没有字符串数据时,我可以让它返回 NULL 吗? 现在我像这样包装每个 str 成员变量:
const wchar* GetName() { // I hate this kinds of wrapping function
if (m_Name.empty())
{
return NULL;
}
return m_Name.c_str();
}
我的工作环境是 Windows 中的 Visual Studio 2008 sp1
提前致谢。
【问题讨论】:
标签: visual-studio string visual-c++ stl