我正在尝试使用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;
}
Run Code Online (Sandbox Code Playgroud)
生成的消息框中没有文本.
这让我相信调用out.str().c_str()返回一个无效的字符串,但我不确定.由于我已经把这个程序缩减到目前为止,我仍然遇到问题,我一定犯了一个令人尴尬的简单错误.感谢帮助!