I’d like to hardcode large sets of data (integer arrays of varying length, a library of text strings, etc) directly into an executable file, so there are no additional files.
My question is, what is the most practical and organized method for doing this in C++? Where would I place the data, in terms of header or source files? What structure should I use?
I realize this isn’t the accepted way of dealing with data. But humour me!
For both C++ and C, you may use header file to put declarations for these variables, and then place actual initialization code into .c (or .cc) file. Both C and C++ have decent initializers syntax. For example:
mydata.h:
mydata.c:
then main.c will have:
test run looks like this:
Now, to really get organized, one would write Perl/Python/PHP script to generate such formed files from your datasources, like SQL database of CSV files.