473,425 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

created file is deleted still program not reporting error

See below the simple program
it opens a file for writing
writes one line at time for 199 times and then comes out.
it also checks before every write, whether file is bad or fail.

Problem : What should happen if someone removes the data file ( i.e. "example.txt" ) using ome command, while this program is running.

I have noticed that it keeps running ( on Linux and Solaris ) and does not report either bad() or fail().

This behaviour somewhat looks obivous. My questions are
1) whether C++ provides any , platform independent , functionallity to handle this case? ( I am looking for some api/function not workarounds like close and open file after every operation )
2) Is there anyway to I use fstat() , for fstream ojbect ?

////////////////////////////////////////////////////////////////////
#include <iostream>
#include <fstream>
//#include <unistd.h>
using namespace std;

int main () {
ofstream myfile;
myfile.open ("example.txt");
int i=0;
for( ;; )
{
//sleep(1);
//for loop for delay
for( int ii=0; ii<10000; ii++)
for( int jj=0;jj<10000; jj++);
myfile <<i++<< " Writing this to a file.\n";
myfile.flush();
if( myfile.bad() )
{
cout<<" its bad now "<<i<<endl;
}
else
{
cout<<" not bad "<<i<<endl;
}
if( myfile.fail() )
{
cout<<" its failed now "<<i<<endl;
}
else
{
cout<<" not failed "<<i<<endl;
}

if( i == 199) break;

}
myfile.close();
return 0;
}
Aug 25 '06 #1
4 1815
Everyony,
I have posted following problem, and would request ur attention to the same.

http://www.thescripts.com/forum/thread527716.html
Aug 28 '06 #2
Banfa
9,065 Expert Mod 8TB
Firstly please don't create extra threads about the same problem, you can always post to the original thread to bump it to the top of the stack.

1. Not particularly, I would kind have expected the OS to prevent deletion of a file opened for writing.

2. fstat does appear to be a member of ofstream or fstream in my reference.
Aug 28 '06 #3
1. OS does not support the NON-deletion of file open for writing.

2. Can , anyone, please tell which reference to look to get details for fstat ( under fstream ). I did looked into http://www.cppreference.com/cppio/index.html , with no luck.

And above all , I shall abide not repeating the same listing with different header
Aug 28 '06 #4
Banfa
9,065 Expert Mod 8TB
2. Further checking suggests that fstat is a *NIX OS function. As such it is very unlikely to be supported by a standard C++ file class so you will not find it mentioned on line in help pages for standard C++. Your implementation may have an extension that provides this functionality, you will have to look in your implementation documentation to determin this.
Aug 28 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dave | last post by:
I created a program using VB6 under WIN 98. The program uses an ado database. When I use the package and deployment program in VB6 on this program and then install it on a machine with XP Pro on...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
9
by: Robert Brown | last post by:
Our customer (of our ecommerce system) wants to be able to preserve deleted entities in the database so that they can do reporting, auditing etc. The system is quite complex where each end user...
9
by: Jon LaBadie | last post by:
Suppose I'm using stdio calls to write to a disk file. One possible error condition is no space on file system or even (in unix environment) a ulimit of 0 bytes. Which calls would be expected to...
6
by: Kiran | last post by:
Hi, I have program, which opens file at the startup and logs error messages to the file, file handle is closed at the end of the program. However if file is deleted in-between, program do not...
2
by: Next | last post by:
Hello all, I have a windows service that was suppose to write some events into its own EventLog. I created the EventLog using the component on VS 2003 toolbar Added an installer for it. Set...
11
by: sur | last post by:
Hello, My problem is that File.Exists works fine if my file is on my local drive but returns false if its on any other drive. I think that the issue is probably file permissions and so I have...
0
by: Silver Oak | last post by:
Hi, I'm experimenting with FileSystemWatcher but it doesn't seem like it fires when a new file is created. Everytime I create a new file, it fires Changed event i.e. Case...
1
by: Donald Grove | last post by:
I am suddenly getting this message. It happens during code executed from a form module that calls a function stored in a standard module. I am working on a standalone pc with no network connection...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.