我期望以下代碼輸出hello5
。相反,它只輸出hello
。 這似乎是一個嘗試輸出一個int到ostringstream
的問題。 當我直接輸出到cout
我收到預期的輸入。在Snow Leopard上使用XCode 3.2。在C++中使用int的ostringstream問題
謝謝!
#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中的主動配置「調試」中的問題產生的。
我使用Microsoft Visual C++ 9.0和Intel C++ Compiler 11.1獲得'hello5'。 – 2009-12-06 02:10:15
http://stackoverflow.com/questions/1416096/c-debug-builds-broke-in-snow-leopard-x-code http://stackoverflow.com/questions/1603300/xcode-3-2-1 -and-c-string-failures – cdespinosa 2009-12-07 05:16:11
這是正確的解決方案。它說將編譯器從GCC 4.2切換到GCC 4.0(在Project Settings,DEBUG配置中)。程序在此之後正確運行。 – 2009-12-07 20:03:55