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

save self-defined object to file?

if i define sth class called card, and further define sth class called deck based on card.

if i want to save such info into a txt/dat file, and then load the info back, how can i do that?

the file currently contains some info like in int/string type.
Apr 7 '08 #1
5 1564
gpraghuram
1,275 Expert 1GB
if i define sth class called card, and further define sth class called deck based on card.

if i want to save such info into a txt/dat file, and then load the info back, how can i do that?

the file currently contains some info like in int/string type.
r u asking how to load the clss info from txt/dat file and create a class at run time?
or u want something else

Raghuram
Apr 7 '08 #2
r u asking how to load the clss info from txt/dat file and create a class at run time?
or u want something else

Raghuram
how to save & load the self-defined class object to and from the txt/dat file?
Apr 7 '08 #3
gpraghuram
1,275 Expert 1GB
how to save & load the self-defined class object to and from the txt/dat file?

i am still not clear?
R u saking how to read the object information froma test file...
You can use fread and fwrite like binary data to di the same.

raghuram
Apr 7 '08 #4
i am still not clear?
R u saking how to read the object information froma test file...
You can use fread and fwrite like binary data to di the same.

raghuram
because i am now using ifstream / ofstream to read / write int and string data to txt file, but not using the binary mode. should i be allowed to use binary mode ONLY to handle my class object data to read / write to txt file? if i change the mode to binary mode, will the current int and string data write / read be affected?
Apr 7 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
You cannot simply write out a string object sicne you don't know how it is implemented. You have to write out the contents of the strings as chars into your file.

As far as the ints go, conver them to chars and write them out.

When you read you cen reconstitute the int from the chars and ditto for the string.

Then you have to know the precise order that you used to write so you know how to read the data back.

You have to remember, that only the built-in types can be written to disc. All user-defined types have to be broken into built-in types for the write operation.

The difference between text an binary is simply whether the newline written to disc is part of the data (binary format) ar a delimiter (text format).
Apr 7 '08 #6

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

Similar topics

2
by: Jim Jewett | last post by:
Normally, I expect a subclass to act in a manner consistent with its Base classes. In particular, I don't expect to *lose* any functionality, unless that was the whole point of the subclass. ...
15
by: aurora | last post by:
This may sound a little crazy. I capture the output of one class by redirecting the sys.stdout. However the is another threading running at the same time and occasionaly it output some messages to...
4
by: HomeyDaClown | last post by:
I'm new to the VB.net world and have been reading alot of books and threw newsgroups Is it even posable to save user input from a form to a data grid. I could just edit the data gri but would...
7
by: WStoreyII | last post by:
how can i save xml. if i have an xml file on a server, lets say a dvd collection. and i have a form that gets information for a new dvd and i append this dvd to the dom. This i can do no problem...
5
by: James Mitchelhill | last post by:
Sorry for the clunky subject line - I have a feeling that not knowing the proper terms for this is part of my problem. I'm trying to write a class that analyses some data. I only want it to do...
5
by: JohnSouth | last post by:
Hi I've seen lots of posts around this subject but nothing recent or very helpful. I've an ASP.Net c# application that needs to read Word documents from a directory on the web server, open...
24
by: Peter Maas | last post by:
The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version): 1. Instance variables can be easily distinguished from local variables. 2. A method from a particular class can be...
84
by: braver | last post by:
Is there any trick to get rid of having to type the annoying, character-eating "self." prefix everywhere in a class? Sometimes I avoid OO just not to deal with its verbosity. In fact, I try to...
6
by: Bart Kastermans | last post by:
I am playing with some trees. In one of the procedures I wrote for this I am trying to change self to a different tree. A tree here has four members (val/type/left/right). I found that self = SS...
5
by: terrybell105 | last post by:
I downloaded Stephan's utility from his website but can't get it to work - or maybe I'm not driving it properly! The form works OK with the existing 3 "views" - I can switch between them and they...
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
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...
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
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...
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...
0
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...
0
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,...
0
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...

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.