473,383 Members | 1,929 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,383 software developers and data experts.

Advanced File I/O questions

Hello Everyone,

I am currently having difficulty understanding File I/O. In one line of code I open an output file in binary mode. In the very next line I check to see if the file is open. What would prevent the file from opening? I know that is_open function returns false if the bad and/or fail bit(s) are set, but no documentation I have read shows an example of how these bits are set.
If someone can show me an example, I would appreciate it. I believe if the computer has 0 bytes left on the hard drive, that would cause opening a new file to fail, but that is only one of at least two scenarios where opening a file would fail.

Thank you,

Kevin
Apr 26 '11 #1

✓ answered by Banfa

The most common cause for a file to fail to open is that it does not exist. Either there has been a typo in the name of the file or the directory is wrong.

Other problems could be a sharing issue, another program already has the file open in a way that prevents your program opening it.

Or may be the disk could be corrupted in a way that prevents it opening.

4 2269
Banfa
9,065 Expert Mod 8TB
The most common cause for a file to fail to open is that it does not exist. Either there has been a typo in the name of the file or the directory is wrong.

Other problems could be a sharing issue, another program already has the file open in a way that prevents your program opening it.

Or may be the disk could be corrupted in a way that prevents it opening.
Apr 26 '11 #2
donbock
2,426 Expert 2GB
Are you checking if the file opened successfully by looking at the value returned by open/fopen or are you calling a separate is_open function?

Whoops! As Banfa explains in the next message, this comment makes no sense for C++. Never mind.
Apr 26 '11 #3
Banfa
9,065 Expert Mod 8TB
Don this is C++, is_open is a member function of fstream/ifstream/ofstream so the return value of open/fopen doesn't really come into it.
Apr 26 '11 #4
In my program, I working solely from the console prompt. This program is similar to notepad. It allows the user to choose between creating a new file, opening the file, and/or editing the file. If the user chooses to edit a non-existent file, should I then give them the choice to create a file?
Apr 29 '11 #5

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

Similar topics

0
by: Jean Hagen | last post by:
We're just getting started with MySQL on Linux; I was browsing my home directory and found a file called .mysql_history. It contains a history of all mysql commands I've entered - including...
4
by: Fredrik Henricsson | last post by:
Hey, I'm building an ontology in Protégé and I want to transform parts of it (e.g. the instances) to HTML with XSL. When I was transforming another file with 'simple' XML-tags like <author> before,...
1
by: John S | last post by:
Hi All, I have several questions about checking backup file : a. When SQL Server receive a command : BACKUP DATABASE test to DISK = '\\pc1\netdb\BTEST', does it verify BTEST file before...
1
by: Patrick Olurotimi Ige | last post by:
When i have a link like :- <a href="sample.xls">download</a> And i want to download ..by clicking the download link it POPS(saying would u like to save or open the file!!) up a dialog box .. But...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
18
by: walterbyrd | last post by:
I am trying to develop an app where: the same file, in the same place, will be uploaded, and then processed. Everything I can find about uploading a file, uses a form that requires the user to...
1
by: alacrite | last post by:
I have a class that represents a record in a database table. class tableName { int col1; string col2; int col3; ... other fields and relevant operations }
2
dmjpro
by: dmjpro | last post by:
suppose i open a file in write mode. if the file exists then the new content will be overwritten and the file opened in append mode then the exsiting file content will be appended. can't i do...
8
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.