Data Saving/Loading & Object Construction

Discussion in 'C++' started by Jerivix Entadi, Feb 23, 2004.

  1. 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.
     
    Jerivix Entadi, Feb 23, 2004
    #1
    1. Advertising

  2. "Jerivix Entadi" <> wrote in message
    news:...
    > 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
     
    John Harrison, Feb 23, 2004
    #2
    1. Advertising

  3. "John Harrison" <> wrote in message news:<c1ca4e$1h0i4i$-berlin.de>...
    > "Jerivix Entadi" <> wrote in message
    > news:...
    > > 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?
     
    Jerivix Entadi, Feb 23, 2004
    #3
  4. Jerivix Entadi wrote:

    > "John Harrison" <> wrote in message news:<c1ca4e$1h0i4i$-berlin.de>...
    >
    >>"Jerivix Entadi" <> 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-lite/serialization.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
     
    Thomas Matthews, Feb 23, 2004
    #4
  5. "Jerivix Entadi" <> wrote in message
    news:...
    > "John Harrison" <> wrote in message

    news:<c1ca4e$1h0i4i$-berlin.de>...
    > > "Jerivix Entadi" <> wrote in message
    > > news:...
    > > > 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
     
    John Harrison, Feb 23, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Kandell
    Replies:
    4
    Views:
    4,167
    eeebop
    Dec 10, 2004
  2. Shahid Juma

    Loading/Saving Data

    Shahid Juma, Mar 29, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    329
    Shahid Juma
    Mar 29, 2006
  3. Ook
    Replies:
    10
    Views:
    558
  4. cantide5ga
    Replies:
    7
    Views:
    391
    cantide5ga
    Oct 23, 2007
  5. JoeC
    Replies:
    2
    Views:
    408
Loading...

Share This Page