Hello,
I recently ran into a problem while porting my c++ application to Xcode on my Mac. The Xcode debug target by default puts the following on the command line:
-D_GLIBCXX_DEBUG=1
This enables something called libstdc++ debug mode which is a feature of the gnu c++ libraries to catch bad code, described here:
http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode.html
My code worked fine until this flag was included. The weird thing is, it also works fine with and without the debug flag on CentOS. It works without the flag on the Mac, but does not work with the flag. I was wondering if anyone could chime in on whether they think this is a bug in my code, or possibly a problem with the Mac OSX libstc++ libraries. Here is a stripped down version:
/////////////////////////
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
int main (int argc, char * const argv[]) {
ostringstream conString;
conString << "Hello, World\n";
conString << "Five is ";
conString << 5 << endl;
string dbCon = conString.str();
cout << dbCon;
return 0;
}
/////////////////////////
When it succeeds, it outputs:
Hello, World
Five is 5
When it fails, it outputs:
Hello, World
Five is
i.e., it has some problem with inserting integers into the stream.
Can anyone see a problem with this code snippet? I find it hard to believe that the Mac OSX libraries have a bug but you never know.
Thanks,
jon