Ofstream << fails writing to file

Hi all,
I have following source which creates a file in the current directory, but << operator doesn't write the line. Can anyone explain why that is happend

It prints "FIle is not opend " line but , actual file doesn't contain line which is written.

struct stat oStBuf;
if (stat(acFile, &oStBuf) != -1)
{
debugLog.open(acFile, ios::app);
cout << " Opened the :: " << acFile << " for appending" << endl;


if (debugLog.is_open() )
{
cout << "File is opened " << endl;
debugLog << "Sample Line of Debug" << endl;
debugLog.flush();
}
else
{
cout << " FIle is not opend" << endl;
}
}
Firstly, the stat function returns 0 (not -1) if the file exists, so your if statement should be:

if (stat(acFile, &oStBuf) != 0)

Also, what are the contents of "acFile". Be sure that it contains the full file name (including the path) and make sure you use double backslashes for the file separator (on Windows).
Topic archived. No new replies allowed.