Ok ok, the subject is a little screamy and not entirely correct but I just came along a nice way to read in data file. Instead of reading the file at runtime why not just format the data and read it in at compile time, using the “#include” preprocessor command? Simple, but I just have never thought of it!

Here is what I mean.

int data[8] = {
#include "./data.txt"
};

When compiling with MSVC10 I have to have the “#include” statement at the beginning of a new line. Not sure if that’s needed for all c or c++ compilers.

Advertisements