1 Replies - 803 Views - Last Post: 18 March 2015 - 07:55 PM Rate Topic: -----

#1 KJG   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-March 15

[C++] Loading a structure from a configuration file

Posted 18 March 2015 - 05:36 PM

Hello :)
I am doing a project in C++ - a simple data base (with "one table").

I want to build that data base using a LIFO or FIFO list, but this doesn't matter here ;)
The only problem I have is that the structure of the data base is not "locked" in the code of the program, but when the program starts, it is "loaded / implemented" from a "configuration file" called "data.txt".
So the user, before she or he runs my program opens the file "data.txt" and writes the structure of the data base that se/he wants to create. This means that one time my program can be used to create a data base of students with fields such as "name / surname / gender / age / idnumber / university" but the next time it can be used for a data base of CD's with fields like - "author / release date / no. of tracks / etc.".
How to do that "loading" of a structure of a data base from a file, when the user runs my data-base creator (my C++ program).
I am sorry for this weird and "repetitive" thoughts. I don't reallly know how to explain it in a good way, so that everyone knows what I ment.
I would very much appreciate even the smallest advie.
Thanks in advance and have a nice day :)

Is This A Good Question/Topic? 0
  • +

Replies To: [C++] Loading a structure from a configuration file

#2 Night Stalker   User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 99
  • Joined: 26-December 13

Re: [C++] Loading a structure from a configuration file

Posted 18 March 2015 - 07:55 PM

The biggest challenge with others writing text files to use your program is getting a consistent protocol. You can't have them writing strings when you're asking for ints. You could write a separate file that does nothing more than creates the text file. In doing that, you insure the data in the text file is in the proper format for your needs. If you are asking how to read/write a text file, then read up on ifstream (Input file streams) and ofstream (output file stream).

This post has been edited by Night Stalker: 18 March 2015 - 07:56 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1