473,624 Members | 2,127 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(ou t,ios::out);
while(!outFile. is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
outFile.open(ou t,ios::out);
}
Jul 22 '05 #1
2 2808
Hi,

"Colum" <co********@hot mail.com> wrote in message
news:PQ******** ********@news.i ndigo.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(ou t,ios::out);
while(!outFile. is_open())
{
cout<<"Please insert disk into A: drive and press key"<<endl;
getch();
outFile.open(ou t,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.i ndigo.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(ou t,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(ou t,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
10591
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. I couldn't figure out which members could be used to check for these types of errors. I tried the good(), bad(), fail() etc., after writing to a full disk, deleted file etc.
6
1886
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 this function. bool processdrecord( ofstream& prnfile, ofstream& validdata, char* record ) { drecord Newdrecord; char customercode;
11
4183
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 I don't know where the problem lies in the code. Can anyone run it through there own compiler please and tell me where and what the problem is. #include <iostream> #include <iomanip> #include <fstream>
3
9121
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++ functions that do this or is there any way I can check manually? Thanks, Prashant
5
18562
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
7851
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 like to know if I am using the fstream methods properly. (as long as I am cleaning up I might as well do it right). By the way, this is just a bogus example with a structure, values and filename for demonstration purposes. PS-> I have a funny...
2
1457
by: coinjo | last post by:
#include<fstream> #include<iostream> #include<cstring> using namespace std; struct date { int day, month, year; };
9
9549
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 function _main assign2.obj Thanks a lot ! Here is the code:
15
5989
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() .... std::ofstream fout; fout.open("hello.out"); fout<<setfill('-')<<setw(20)<<"-"<<setfill(' ')<<endl; fout<<"hello "; // this is line 139
0
1693
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 pass... ex: pass: 01 11110000 - file 01010101 - pass (repeated until EOF) 10100101 - resulting file decryption would be the exact same process, but i've made it slightly more complicated. first at the beginning of the file I have a...
0
8172
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
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 we have to send another system

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.