【发布时间】:2009-12-06 02:03:22
【问题描述】:
我希望下面的代码输出hello5。相反,它只输出hello。
尝试将 int 输出到ostringstream 似乎是一个问题。
当我直接向cout 输出相同内容时,我收到了预期的输入。在雪豹上使用 XCode 3.2。
谢谢!
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
int myint = 5;
string mystr = "hello";
string finalstr;
ostringstream oss;
oss << mystr << myint;
finalstr = oss.str();
cout << finalstr;
return 0;
}
编辑:请参阅我在下面发布的答案。这似乎是由 Snow Leopard 上 XCode 3.2 中的 Active Configuration 'Debug' 中的问题造成的
【问题讨论】:
-
我使用 Microsoft Visual C++ 9.0 和 Intel C++ Compiler 11.1 得到
hello5。 -
这是正确的解决方案。它说将编译器从 GCC 4.2 切换到 GCC 4.0(在项目设置,调试配置中)。之后程序正常运行。