Anyone writing C++ code will want to read in a file and do something with the data contained within. That is usually simple:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream readfile("example.txt", ifstream::in);
string line;
if(!in.is_open()){
cerr << "File not found!" << endl;
} else {
getline(readfile,line);
cout << line << endl;
}
readfile.close();
return 0;
}
For some reason that no one seems to comprehend Xcode sets preprocessor flags which are inconsistent with the standard libraries it ships with. Specifically:
_GLIBCXX_DEBUG=1
_GLIBCXX_DEBUG_PEDANTIC=1
Fortunately this can be easily fixed on a per-project basis by removing the offending lines from Project>>Edit Active Target “…”>>Preprocessor Macros. The easiest way to find it is to search for ‘preprocessor’ in the Active Target configuration. It should look something like the image below when done.
A more pervasive and lasting solution is to edit the project templates in ‘/Developer/Library/Xcode/Project Templates.’ You can find exactly which template are offending using the following command:
find '/Developer/Library/Xcode/Project Templates' -name "project.pbxproj" -exec grep -l "_GLIBCXX_DEBUG=1" \{\} \;
You will want to remove the two offending definitions in code that resembles that below:
GCC_PREPROCESSOR_DEFINITIONS = (
"_GLIBCXX_DEBUG=1",
"_GLIBCXX_DEBUG_PEDANTIC=1",
);
Hope this saves others time.