Xcode/cout/complex problem

Hi,


I have tried a few fora with this query and so far no luck. The following really simple segment:


#include <iostream>
#include <complex>
int main (int argc, char * const argv[])
{
std::complex<double> a(1.,1.);
std::cout << "a = "<< a << "\n";
return 0;
}


using Xcode 3.2 (the project setting is 'Command Line tool') on OSX 10.6.8 compiles fine and produces the following output:


a = (



when of course it should produce:


a = (1.,1.)


Yes, I can display the real and imaginary parts using a.real(), a.imag() but the above should work.


Any ideas why Xcode has this weird behaviour?

Has anyone else seen this?

Thanks in advance,

mk ii

Xcode 3.2-OTHER, Mac OS X (10.6.8)

Posted on Jan 24, 2013 3:30 PM

Reply
7 replies

Jan 25, 2013 7:59 AM in response to mk ii

mk ii wrote:


It isn't the gcc compiler, the code segment works fine if compiled using g++ in the terminal, it is almost certainly a bug in Xcode.

Xcode is just an IDE. It uses the GCC compiler. You might want to double-check that you are using the correct C++ template and try running your program from the terminal instead of from Xcode. There could be some iostream buffering issues that aren't working properly when you are running from inside Xcode.

Jan 26, 2013 2:54 AM in response to mk ii

Try adding either a newline in your output string or add "std::endl" (a newline character automatically flushes), or add an implicit std::flush.


XCode adds a wrapper around the console, and it simply might not be aware that you are done writing a string. Flushing tells it you *are*. It "works" correctly in Terminal because this automatically flushes at the end of a program.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Xcode/cout/complex problem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.