我尝试使用std :: ostringstream将数字转换为字符串(char *),但似乎无效。这是我的代码:
#include <windows.h>
#include <sstream>
int main()
{
std::ostringstream out;
out << 1234;
const char *intString = out.str().c_str();
MessageBox(NULL, intString, intString, MB_OK|MB_ICONEXCLAMATION);
return 0;
}
结果消息框中没有任何文本。
这让我相信,调用out.str().c_str()
返回了一个无效的字符串,但我不确定。由于我已经缩减了这个程序并仍然遇到问题,所以我一定犯了一个非常简单的错误。希望能得到帮助!