Hi,

Here's my scenario. I am given records and the datastructure of each column in the records at runtime. A sample looks like this,

char[] | int16 | int32 | double
abcd   | 2     | 96    | 1024 
ghi    | 3     | 104   | 2048

I cannot predefine a structure because I dont know what data types I am gonna be given.How can I store the records? I was thinking of declaring a multidimensional double array and typecasting all the records and then casting back whenever necessary. Does this seem sensible? Is there a better solution?

for a example here , you declare a union like this.

union DataStructure
{
  char mCharPtr[20];
  short mInt16;
  int   mInt32;
  double mDouble;
};

and the size of the DataStructure is just 20. not 20+2+4+8 =40.

and if you still can't understand just go and do a exercises on this
page.
http://www.yolinux.com/TUTORIALS/LinuxTutorialC++Structures.html
you will understand why so.And still not understood just ask.

Edited 6 Years Ago by NicAx64: n/a

look into boost::any

>>I cannot predefine a structure because I dont know what data types I am gonna be given

Why not? Well do you at least know if its a string or a number?

This seems like a ridiculous task. What about taking the input, and sorting it into different vectors depending on what column it's in? You could probably catch all possibilities with a std::string vector, a double vector, and a int64 vector. Route all strings to the string vector, all floats and double to the double vector, and every size of integer to the int64 vector.

This article has been dead for over six months. Start a new discussion instead.