c++ loading large amount of data at compile time
c++, visual-studio-2010
Solution
Something like:
class object
{
public
object(){ double a[] = {
#include "file.h"
};
/* rest of code here*/};
private:
/* code here*/
}
The file has to be formatted correctly though - i.e. contain something like:
//file.h
23, 24, 40,
5, 1.1,
In general, you can use `#include` directives to paste content into files. I've seen `virtual` methods being pasted like that, if they were common for most derived classes. I personally don't really like this technique.
Problem
I have a C++ object which needs a huge amount of data to instantiate. For example: ``` class object { public object() { double a[] = { array with 1 million double element }; /* rest of code here*/}; private: /* code here*/ } ``` Now the data (i.e 1 million double numbers) is in a separate text file. The question: How can I put it after "double a[]" in an efficient way and eventually compile the code? I do not want to read the data at run time from a file. I want it compiled with the object. What can be a solution? Ideally I would like the data to sit in the separate text file as it presently resides and somehow also have an assignment like double a[] =..... above. Is this possible? Thanks in advance!