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

Best way to open files

I have implemented a class which performs operations on some file
throughout different methods in the class.

I did this by making the ifstream a private class member and opening the
file in the constructor,

however someone told me this was bad practice to have the stream as a
class attribute.

what is the best way to do it?
Jul 23 '05 #1
1 1440
On 2005-04-08, Dave Mill <da******@davemill.com> wrote:
I have implemented a class which performs operations on some file
throughout different methods in the class.

I did this by making the ifstream a private class member and opening the
file in the constructor,

however someone told me this was bad practice to have the stream as a
class attribute.


Not sure why -- but here are two issues:
(1) you can't copy or assign. Not necessarily a problem, but depends on how
you're using it. You've got to think about whether the object you're modelling
can truly be "copied".
(2) stack space: sizeof(ifstream) is 280 on my compiler, so it's very waste
to create streams that you're not using

About (2): you can use pointer and dynamically allocate when you use it.
About (1): use a shared pointer if you want a working copy constructor and
assignment.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
Jul 23 '05 #2

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

Similar topics

33
by: Frank | last post by:
What is the best IDE for developing PHP applications? What do you use and why? Thanks.
4
by: Frank Millman | last post by:
Hi all I need to generate potentially large reports from a database, and I want to offer the option of print preview before actually printing (using wxPython). I figure that the best way to...
5
by: Richard Fagen | last post by:
Hi Everyone, I have been writing xBase applications for many years but I am new to VB/SQL for larger applications. In xBase, I would start the main program (form) by opening up all the...
0
by: David Helgason | last post by:
I think those best practices threads are a treat to follow (might even consider archiving some of them in a sort of best-practices faq), so here's one more. In coding an game asset server I want...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
4
by: Arthur Pemberton | last post by:
What is the best way to do data source abtraction? For example have different classes with the same interface, but different implementations. I was thinking of almost having classA as my main...
18
by: stylecomputers | last post by:
Hi All, What do you find the best IDE for creating web applications in Python is? Preferably FOS IDE. Cheers
6
by: JM | last post by:
I have never used a (content management system) CMS before but I need one for my internship as a webdeveloper. Requirements: runs on Apache, linux or unix, MySQL and PHP (maybe Windows server...
12
by: MrQuan | last post by:
G'day all, I have a requirement to communicate between two or more PCs over the Internet, however I have no idea how to go about this. I'm not talking about a chat programme as such, I want to...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
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:
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
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: 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
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
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...

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.