Ostringstream problem with int in C ++

I expect the following code to output hello5 . Instead, it only displays hello . The problem seems to be related to trying to output int to ostringstream . When I output the same directly to cout , I get the expected input. Using Xcode 3.2 on Snow Leopard.

Thanks!

 #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; } 

EDIT: see the answer I posted below. This seems like a problem in "Debugging" Active Configuration in Xcode 3.2 on Snow Leopard

+4
source share
4 answers

Changing the active configuration in Xcode from "Debug" to "Vacation" works as a workaround.

+4
source

Your code is correct, it writes hello5 on my Windows 7 machine. Perhaps the problem is that you are not writing std :: endl or something that can confuse your OS.

+3
source

Yep tested for this purpose (Windows XP Pro) and it runs smoothly

+2
source

I just tested and it worked perfectly on my Mac with Xcode 3.2.1 and Snow Leopard. This does not mean that your invitation hides the conclusion? Try adding endl to the cout line?

- Change -

My test suite

  • c++ test.cpp - works great
  • c++ -D_GLICXX_DEBUG=1 test.cpp - fail
  • c++ -arch i386 -D_GLICXX_DEBUG=1 test.cpp - works great

What can we say about this? In short, the Debug version of 64-bit stdC ++ seems to be broken.

+1
source

All Articles