Read a delimited flat file with fields on first row

Hello everyone,

I`d need to read a typical text file with an unknown number of fields (and type, but let´s supose the are all char-type). The name of that fields is stored on the first row of the file. The file is delimited with a character, for example the | character.

the goal is to read the file and store the content of the file into a database. Then the question is : Is it possible to generate a struct dinamically from the information given in the first row? Is a struct the correct way to solve it? I can´t figure out a possible solution for this.

Thank you in advance.
Regards
No. Structs are by definition static constructs. What you need is a dynamic type system.
For example:
1
2
3
class Object;
class Integer:Object;
class String:Object;

Then the structure that will hold a record would look like this:
1
2
3
class Record{
    std::vector<Object *> fields;
};
helios wrote:
What you need is a dynamic type system.

You more or less already have a dynamic type system in the database. Just read all of the data into a vector of strings. Then use the database API to coerce the strings into the field types they map to.
Yeah, that works too.
thank you for the answers.. the fact is I used the tern database to simplify the question, but I want to create a my own "database" and the parsing of the text file would go to a "table" , that would be a binary file. So i get the idea about using dynamic types and vectors, even I'll need a more complex structure of classes, that store other information like the name of the field , the vectors read and other propertiers and functions..
Topic archived. No new replies allowed.