By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

Data Saving/Loading & Object Construction

P: n/a
I'm attempting to create an application to work with a fluid database
of people. I'm doing this in a command line, text-based manner. I need
to know two things: 1) How do I save data, perhaps a group of objects
and their memebers or a few lines of text? and 2) Is there any way to
automate object construction? I'm thinking that I can create a vector
or something similar to handle the number of people, is there a way
for me to write a function that will create a default object for each
of these people?

Any answers or directions to answers would be greatly appreciated.
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Jerivix Entadi" <je*****@hotmail.com> wrote in message
news:86*************************@posting.google.co m...
I'm attempting to create an application to work with a fluid database
of people. I'm doing this in a command line, text-based manner. I need
to know two things: 1) How do I save data, perhaps a group of objects
and their memebers or a few lines of text?
It's up to you how you save the data. I think you're asking about whether
you should save as binary data or text. This really depends on what you want
to do with the data. Binary would be the traditional approach but these days
XML should be considered since it will enable your data to be processed by
all the XML parsers that are out there.
and 2) Is there any way to
automate object construction? I'm thinking that I can create a vector
or something similar to handle the number of people, is there a way
for me to write a function that will create a default object for each
of these people?
I don't really understand this question either. You can write any
constructor you like, does that count as automatic object construction?

Any answers or directions to answers would be greatly appreciated.


I think a bit more detail in the question will get you more help.

john
Jul 22 '05 #2

P: n/a
"John Harrison" <jo*************@hotmail.com> wrote in message news:<c1*************@ID-196037.news.uni-berlin.de>...
"Jerivix Entadi" <je*****@hotmail.com> wrote in message
news:86*************************@posting.google.co m...
I'm attempting to create an application to work with a fluid database
of people. I'm doing this in a command line, text-based manner. I need
to know two things: 1) How do I save data, perhaps a group of objects
and their memebers or a few lines of text?


It's up to you how you save the data. I think you're asking about whether
you should save as binary data or text. This really depends on what you want
to do with the data. Binary would be the traditional approach but these days
XML should be considered since it will enable your data to be processed by
all the XML parsers that are out there.
and 2) Is there any way to
automate object construction? I'm thinking that I can create a vector
or something similar to handle the number of people, is there a way
for me to write a function that will create a default object for each
of these people?


I don't really understand this question either. You can write any
constructor you like, does that count as automatic object construction?

Any answers or directions to answers would be greatly appreciated.


I think a bit more detail in the question will get you more help.

john

Let me carify a bit. I don't know how to even save as binary data or
XML. I've done a bit of experimentation with saving single lines of
text, but past that I really don't know much.

As far as object creation goes, I'm not worried about the constructor
itself, but rather defining the objects in the first place. Is there
any way to write soemthing that will create the objects for me?

In other words, if I have a Class People, and the user inputs "Betty",
can I then pass "Betty" into a function that will create an object for
Betty and let the constructor etc. take it from there?
Jul 22 '05 #3

P: n/a

"Jerivix Entadi" <je*****@hotmail.com> wrote in message
news:86**************************@posting.google.c om...
"John Harrison" <jo*************@hotmail.com> wrote in message news:<c1*************@ID-196037.news.uni-berlin.de>...
"Jerivix Entadi" <je*****@hotmail.com> wrote in message
news:86*************************@posting.google.co m...
I'm attempting to create an application to work with a fluid database
of people. I'm doing this in a command line, text-based manner. I need
to know two things: 1) How do I save data, perhaps a group of objects
and their memebers or a few lines of text?


It's up to you how you save the data. I think you're asking about whether you should save as binary data or text. This really depends on what you want to do with the data. Binary would be the traditional approach but these days XML should be considered since it will enable your data to be processed by all the XML parsers that are out there.
and 2) Is there any way to
automate object construction? I'm thinking that I can create a vector
or something similar to handle the number of people, is there a way
for me to write a function that will create a default object for each
of these people?


I don't really understand this question either. You can write any
constructor you like, does that count as automatic object construction?

Any answers or directions to answers would be greatly appreciated.


I think a bit more detail in the question will get you more help.

john

Let me carify a bit. I don't know how to even save as binary data or
XML. I've done a bit of experimentation with saving single lines of
text, but past that I really don't know much.


File I/O (binary or text) is done in C++ with the iostream library. That's
rather a big topic to cover in a newsgroup post.

As far as object creation goes, I'm not worried about the constructor
itself, but rather defining the objects in the first place. Is there
any way to write soemthing that will create the objects for me?

I'm sure there is.
In other words, if I have a Class People, and the user inputs "Betty",
can I then pass "Betty" into a function that will create an object for
Betty and let the constructor etc. take it from there?


Seems a bit confused, you say 'create an object for Betty and let the
constructor etc. take it from there' but it is the constructors job to
create objects, nothing else's.

You can certainly write a function that given a persons name will create an
object for that person.

Person create_person(std::string name)
{
// create the person here
}

Of course you have to fill in the part indicated by the comment 'create the
person here'

But I sense you are asking for something more, since the above code is
completely straightforward. Unfortunately I'm still not sure what that is.

john
Jul 22 '05 #4

P: n/a
Jerivix Entadi wrote:
"John Harrison" <jo*************@hotmail.com> wrote in message news:<c1*************@ID-196037.news.uni-berlin.de>...
"Jerivix Entadi" <je*****@hotmail.com> wrote in message

Let me carify a bit. I don't know how to even save as binary data or
XML. I've done a bit of experimentation with saving single lines of
text, but past that I really don't know much.

As far as object creation goes, I'm not worried about the constructor
itself, but rather defining the objects in the first place. Is there
any way to write soemthing that will create the objects for me?

In other words, if I have a Class People, and the user inputs "Betty",
can I then pass "Betty" into a function that will create an object for
Betty and let the constructor etc. take it from there?


Search the newsgroups and web for "Design Pattern Factory".
This is a pattern used for creating instances given an indentifier
of some sort.

As for writing objects, the trick is to have each object provide
a method (or overload an existing operator) to write (and read)
each member. If the member is not a simple type, then it should
have read and write methods too.

The methods to use are the I/O streams. Also search the newsgroups
and web for "Serialization OR permanent C++". See the C++ FAQ:
http://www.parashift.com/c++-faq-lit...alization.html

One should always research the FAQ and search the newsgroups
(as well as the web) before posting. You can search for
"Thomas Matthews binary write" for some replies I've posted.
{Although I have improved the code a bit since then.}

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.