473,378 Members | 1,094 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,378 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 1813
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.