Sign in to follow this  

Can't get ofstream to open or write!

This topic is 3667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is just plain weird. I have a thread in which I have included fstream and created an ofstream. I know the lines are being executed because I have set breakpoints and they get hit. But no file opening, and nothing writing?!! TetClientSink.h:
#include "trackedWindow.h"
#include <fstream>
using namespace std;

... //other declarations

ofstream tetFile;
TetClientSink.cpp
CTetClientSink::CTetClientSink(CTrackedWindow *pTrackedWindow)
{
	m_dwRef = 0;
	m_pTrackedWindow = pTrackedWindow;
	tetFile.open("eyeLog.out", ios::app);
	tetFile << "I'm here!";
	tetFile.flush();
}
Does this possibly have anything to do with the fact it's a thread? That's the one aspect of this code I don't feel I have a perfect understanding of. Let me know if posting the fstream buffer contents before/after any of the tetFile code. thanks ~Lykaios

Share this post


Link to post
Share on other sites
probably "eyeLog.out" does not exist, or it does not find it because the working directory variable is not what you think, causing the append file stream to cancel?

Share this post


Link to post
Share on other sites
Quote:
Original post by yahastu
probably "eyeLog.out" does not exist, or it does not find it because the working directory variable is not what you think, causing the append file stream to cancel?

Or you don't have write access to the file.

However, i seem to recall this should cause an error when you try to write to the file. Since it isn't, you might try testing the file after opening, like this:
 If (!tetFile) std::cerr << "PANIC!" << std:endl;

Share this post


Link to post
Share on other sites

This topic is 3667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this