Looking for Tutorial (C++)

Discussion in 'Mac Programming' started by dq9, Jan 30, 2011.

  1. dq9 macrumors newbie

    Joined:
    Mar 13, 2008
    Location:
    Macintosh HD/Users/dq9
    #1
    Hi I am looking for a tutorial on making a simple command line database with C++. Something like an address book or something simple like that. I'm thinking of storing all the information in an external file, so that I can be saved/altered.

    Basically I am looking to be able to:
    • Save and load data from an external file (.dat, .txt, etc...)
    • Search through that data
    • Display searched results

    Any help will be greatly appreciated.
     
  2. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #2
    I'd suggest telling us a little more about yourself; current programming knowledge and experience if any.

    Redirect from there.
     
  3. dq9 thread starter macrumors newbie

    Joined:
    Mar 13, 2008
    Location:
    Macintosh HD/Users/dq9
    #3
    I program on the side and as a hobby. I am a beginner / intermediate programmer with basic to intermediate knowledge of C++. I have messed around with file I/O before, but not a whole lot.

    I also think I should add that I'm not looking to connect to a MySQL database with this project. I want everything to be local. I did a google search that connecting to a MySQL database came up a lot.
     
  4. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
  5. xlii macrumors 68000

    xlii

    Joined:
    Sep 19, 2006
    Location:
    Millis, Massachusetts
    #5
    Well you could buy a book... but there are also online resources...

    See the online tutorial under documentation....

    http://www.cplusplus.com/
     
  6. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #6
  7. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    Do you want to complete this one task and that will be that, or do you want to build on your knowledge so you can complete many tasks like this in the future?

    -Lee
     
  8. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #8
    Perhaps more specific a question that some of the others have asked. How did you learn the C++ you know. What books did you read or or courses did you take?

    MySQL can definitely still be local, but you could use something else like BDB http://en.wikipedia.org/wiki/Berkeley_DB instead of rolling your own.

    B
     
  9. dq9 thread starter macrumors newbie

    Joined:
    Mar 13, 2008
    Location:
    Macintosh HD/Users/dq9
    #9
    I will definitely use it to expand my knowledge in the future.

    I'm entirely self taught. I learned from cprogramming.com mostly and also cplusplus.com


    The program I am looking to create will be a command line address book with a name, phone number, and e-mail, field. That's what I have thought up so far. I want to save all this information into a .txt file (To make things simple for now).
     
  10. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #10
    From your somewhat terse descriptions I believe the C++ STL provides everything you need.

    Your data files could consist of nothing more than strings with fields separated by some marker character literal.

    Using strings, iostreams, stringstreams and either/or/both of map/vectors.

    Discuss the data you'd like to track, read, store and search for and someone'll be more than glad to make further suggestions.
     
  11. dq9 thread starter macrumors newbie

    Joined:
    Mar 13, 2008
    Location:
    Macintosh HD/Users/dq9
    #11
    I'm looking to search for, write, and read strings from a file.
     
  12. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #13
    Something that hasn't been discussed yet but do you need to store anything beyond pure ASCII characters.
     
  13. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #14
    For an address book, I would create an address book entry class and an address book class. Your address book would hold a data structure inside and use methods to insert, search, remove entries and so on. The simplest way to do this is probably to just use a vector, it's enough unless you intend to store millions of entries IMO. You would need to read up on serialization to be able to come up with a way to write and read your data structure from disk.

    This all assumes that the goal here is to create everything your self. Other wise look into SQLite, which gives you an in memory SQL data base.
     
  14. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #15
    I think this is where the sites you have been using fall apart as a learning tool, and I would recommend you check out some more structured resource like a book.

    Maybe not something like the typical Strostrup http://www.amazon.com/C-Programming-Language-Special/dp/0201700735 but maybe something more like C++ Cookbook http://oreilly.com/catalog/9780596007614/ or Practical C++ Programming http://oreilly.com/catalog/9780596004194/ that already assume some knowledge.

    I haven't actually read C++ Cookbook, but other O'Reilly Cookbooks have been very useful and I believe it introduces Boost and STL.

    B
     

Share This Page