Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pliuya

macrumors newbie
Original poster
Feb 20, 2010
3
0
I just started using Xcode and met with a very weird question while outputting results to file. Codes are follows:
#include <iostream>
#include <math.h>
#include <fstream>

using namespace std;

int main()
{

ofstream trial;
trial.open("trial.txt");
trial << "****" << endl;
trial << (5+3) << endl;
return 0;

}
The outputs in trial.txt are
****
I suppose to see 8 but it doesn't appear. However, the results are correct when output to console:
****
8

Does anyone have idea why it happened? Your help will be highly appreciated.

Best,
Stanley
 
You're not closing the stream, so the buffer isn't being flushed and the file contents not written.
 
Thank you, but not the case.

Even I add trial.close(), the problem is still there. I am pretty sure it is due to Xcode. Maybe I miss something in the configuration. There is no problem when I run it using Eclipse.
 
We get this question every couple days. It's actually an Xcode bug. Edit your target settings and look for this:

Preprocessor Macros = _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1


Highlight the line, and press the delete key on your keyboard. Now try again.
 
Thanks. It works.

Thank you, Detrius! I follow what you say:
1. Project -> Edit Active Target ...
2. Search for "preprocessor" in Build
3. Delete the value.

It works correctly!!:):):)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.