|
|
#1 |
|
cout << complex weird problem!
Hi,
The following segment: Code:
#include <iostream>
#include <complex>
int main (int argc, char * const argv[])
{
std::complex<double> a(1.,1.);
std::cout << "a = "<< a << "\n";
return 0;
}
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 / OSX has this weird behaviour? Has anyone else seen this, any suggestions? Cheers, m |
|
|
|
0
|
|
|
#2 | |
|
cout and output
Quote:
Code:
g++ main.cc -o cout You could try to force a "flush" of the output buffer, using std::cout.flush(); after you print the complex number, i.e. Code:
#include <iostream>
#include <complex>
int main (int argc, char * const argv[])
{
std::complex<double> a(1.,1.);
std::cout << "a = "<< a << "\n";
std::cout.flush();
return 0;
}
-DrSoong |
||
|
|
0
|
|
|
#3 |
|
Thanks drsoong,
I tried std::cout.flush(); but it made no difference. Like you say it is almost certainly an Xcode problem, I would use a terminal and g++ but it is a largish project so Xcode is useful. For portability reasons I hope to get to the bottom of it rather than writing cout << "a=" << a.real() << a.imag() everywhere. mk ii |
|
|
|
0
|
|
|
#4 | |
|
Quote:
Also, I believe I have encounter a similar problem with cout not displaying everything it should when run in Xcode on Snow Leopard. The issue doesn't show up in Xcode on Lion/Mountain Lion, nor does the bug manifest itself in Terminal for any version of OS X that I have.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed. Like it on Facebook! |
||
|
|
0
|
|
|
#5 |
|
Works on latest Xcode
Tried it on latest xcode (download today) / latest os. Works without problems inside xcode. Not tried in terminal (tell me if I should)
My guess is that it is a bug that has been fixed. Might not help OP though. // Gunnar |
|
|
|
0
|
|
|
#6 |
|
When I was in College taking C++ classes I had a lot of trouble with XCode's output window so I stuck to compiling and then running my programs in the terminal. This likely has gotten better over the past two years or so but when in doubt, run the program in the terminal.
|
|
|
|
0
|
|
|
#7 |
|
This should work as expected without the need for an explicit flush. This is likely an Xcode bug. I would recommend upgrading to a newer version or reporting the issue to Apple (and pray for a fix).
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 01:51 PM.




when of course it should produce:


Linear Mode
