double speedTest()
	double dInitialTime = clock(), dFinalTime = 0;
	double dRepititions = 99999999;
	double dResult;
	cout << "\nCalculating...\n\n";
	for(int nCounter = 0; nCounter <= dRepititions; nCounter++)
		pow(dRepititions, pow(dRepititions, dRepititions));
	dFinalTime = clock();
	dResult = dFinalTime - dInitialTime;
	ofstream outf("Results.dat", ios::app);
    outf << dResult << endl;
	return dResult;

I created this function (as part of a larger program) a while back, but when I upgraded to Xcode 4, seemingly ofstream does not work anymore. While the code compiles, noting is written to the file when this function is called. I've looked over it, but can't seem to find anything wrong with it. Any thoughts? Thanks

Recommended Answers

All 15 Replies

try to put outf.close(); before your return statement.

worked ok for me on MS-Windows 7 and vc++ 2010 express.

Strange. Still doesn't work. Nothing is being written to the file. Here is my output function (to show all test results):

void allResults()
	string fileReading;
	double fileCounter = 0;
	cout << "All test results, from the very first:\n";
	ifstream inf("Results.dat");
	inf.seekg(0, ios::beg);
		getline(inf, fileReading);
		cout << "\nTest " << fileCounter << ": " << fileReading;
	cout << "Next test. Enter 'r' to retest!\n";

I though maybe there was an error there, yet it used to work and, after all, nothing is being written to the file, so actually this function is doing what it should: simply displaying "Next test. Enter 'r' to retest!" So.....

I now realize I could use a for loop instead in the output function:

for( double fileCounter = 1; inf; fileCounter++)
		getline(inf, fileReading);
		cout << "\nTest " << fileCounter << ": " << fileReading;

But that is irrelevant. Any ideas why this builds fine but does not work properly with Xcode 4.0.2 on OS X 10.6.7?

eh... bump

commented: Do NOT bump threads. It's extremely rudt to wait a measly 30 minutes -- most of us have lives. -3
commented: i'll show you a bump -2

could it be a permissions problem? Does the program have required write permissions? Change the path of the output file to somewhere you know has ok permissions, such as your home directory.

Gah, it is already in my home directory! I have another program that is supposed to create a url file (to the same directory) with a single web address as the only contents, and writing the contents of it worked fine! So there's nothing wrong with my syntax, right?

Where is function speedTest() being called? Add some code inside that function to make sure its being called. Also just comment out the loop on lines 7-10 to make sure that isn't causing a problem.

What does your error checking tell you of the open and write?

@Ancient Dragon- I commented out the loop you mentioned, and also the loop in the code that calls speedTest(). Neither had any effect.

@WaltP- Error checking gives me nothing. Apparently, nothing is wrong, but still, eh, wrong. Very strange, as the program worked with old Xcode, and I'm quite sure I didn't change anything, but when I updated to Xcode 4 I have problems.

when I updated to Xcode 4 I have problems

You and everyone else. Did you hear that Apple's bug reporting server crashed after they released Xcode 4 due to the load?

Oh boy, I heard that there were problems with the installation and that the installer was much larger than it should be, but I didn't know about that! Well I guess it is a problem with Xcode; I know the function is being called and the syntax looks alright. I hope I don't need another 5GB download for the next Xcode update.

Maybe changing from XCode is in order...

Yes, but Xcode is the only objective-c IDE for mac............................................... *cries*

Alright.... thanks for the help everyone

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.