所以我在按钮点击方法中有那个简单的代码:
std::stringstream ss;
unsigned counter = 0;
while(true)
{
ss.clear();
ss << DEFAULT_USER_CONFIG_NAME << " " << ++counter;
const char* name = ss.str().c_str();
MessageBox(name);
/* ... while break condition */
}
问题是消息框是空的。但是当我直接传递文本时它可以正常工作:
MessageBox(ss.str().c_str()); // that shows text just fine
我在调试器中发现的是没有创建局部变量“name”(至少它没有在调试器中显示)。任何线索为什么它在直接通过时工作而在其他情况下失败?此外,当我将“名称”转换为 CString 时,它在 IsEmpty() 检查时返回 true。