473,499 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error using ofstream close()

Hi,
I am trying to write data out to a file on floppy disk,
If the disk is present in the drive the program runs fine and outputs the
data correctly, however if the disk is not present in the drive, the program
enters the while loop which asks user to insert the disk and continuously
tries to open it, after the user has inserted the disk the program seems to
run fine, however there is no data in the output file.I think it could be a
problem with close() (not having a handle to the file) not opperating
properly, some code used:-

outFile.open(out,ios::out);
while(!outFile.is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
outFile.open(out,ios::out);
}
Jul 22 '05 #1
2 2796
Hi,

"Colum" <co********@hotmail.com> wrote in message
news:PQ****************@news.indigo.ie...
Hi,
I am trying to write data out to a file on floppy disk,
If the disk is present in the drive the program runs fine and outputs the
data correctly, however if the disk is not present in the drive, the program enters the while loop which asks user to insert the disk and continuously
tries to open it, after the user has inserted the disk the program seems to run fine, however there is no data in the output file.I think it could be a problem with close() (not having a handle to the file) not opperating
properly, some code used:-

outFile.open(out,ios::out);
while(!outFile.is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
outFile.open(out,ios::out);
}


Well, if this is the program there shouldn't be any data in the outFile,
where is the part that is writing data in it?

Regards, Ron AF Greve.
Jul 22 '05 #2
Colum wrote in news:PQ****************@news.indigo.ie:
Hi,
I am trying to write data out to a file on floppy disk,
If the disk is present in the drive the program runs fine and outputs
the
data correctly, however if the disk is not present in the drive, the
program enters the while loop which asks user to insert the disk and
continuously tries to open it, after the user has inserted the disk
the program seems to run fine, however there is no data in the output
file.I think it could be a problem with close() (not having a handle
to the file) not opperating properly, some code used:-

outFile.open(out,ios::out);
while(!outFile.is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
You need to clear the error state before you can succesfully retry
the open.

outFile.clear();
outFile.open(out,ios::out);
}


HTH.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10548
by: steve | last post by:
Is there a way to catch file errors while writing to a file using ofstream? For ex., if the file is deleted or permissions changed by another process after it is opened, or when the disk is full....
6
1878
by: muser | last post by:
In the following function there is an access violation error, some memory can't be read. A week ago this code did compile. Can anyone possibly tell me why my compiler is unable to read part of...
11
4163
by: muser | last post by:
In the code I supplied before this one, the cause of the problem is an access violation error. When I run the debugger it skips into what I can only assume is the compilers version of my code. And...
3
9074
by: jois.de.vivre | last post by:
Hi, I'm trying to write to an ofstream, and for some reason it fails. I know I can check it with fail() or bad(), but it gives me no useful information as to why it fails. Are there any C++...
5
18507
by: Squid Seven | last post by:
I'm trying to use a pointer to an ofstream object and having problems: ofstream *sessionFile = NULL; if( directory == "" ) sessionFile = new ofstream( fileName.c_str(), ios::out ); else {
4
7832
by: adamrobillard | last post by:
Hi, I have always used fopen and FILE* to load and save structures to file. I am trying to convert all the older code to use proper C++ calls... the following code works properly but I would...
2
1452
by: coinjo | last post by:
#include<fstream> #include<iostream> #include<cstring> using namespace std; struct date { int day, month, year; };
9
9542
by: Trent | last post by:
Here is the error while using Visual Studio 2005 Error 1 error LNK2019: unresolved external symbol "void __cdecl print(int,int,int,int,int,int,int,int)" (?print@@YAXHHHHHHHH@Z) referenced in...
15
5968
by: aaragon | last post by:
Hello, does anyone have a clue about this error? and how to solve it? It seems to be trivial to me, but not for the compiler. I'm using g++ 4.2 on an Ubuntu Linux system: // main() .......
0
1679
by: Craftkiller | last post by:
=========Program compiles on both windows and linux=========== Greetings, I am currently working on an encrpytion program that will take a file and a password string and flip the bits based on the...
0
7007
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...
1
6893
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
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
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
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.