B
Brad Marts
I have a file containing numbers stored in binary form and information in
ascii which tells me what kind of numbers they are (int, float, double,
etc.). I want to be able to read in the numbers and wind up with eg
vector<int> if the numbers are ints. It's not known until run-time what
the type of the numbers will be.
If I knew there would be 10 ints, I could write something like:
int numbers[10]
ifstream in("file.bin");
char line[256]
in.getline(line,255); // eg, the first line would contain "int\n"
in.read( (char *) &numbers, 10*sizeof(int));
in.close();
I could write a template function to do this, but I won't know until
run-time what the type will be. Do I have to use a switch to select which
function to use? Or is there a better way?
Brad
ascii which tells me what kind of numbers they are (int, float, double,
etc.). I want to be able to read in the numbers and wind up with eg
vector<int> if the numbers are ints. It's not known until run-time what
the type of the numbers will be.
If I knew there would be 10 ints, I could write something like:
int numbers[10]
ifstream in("file.bin");
char line[256]
in.getline(line,255); // eg, the first line would contain "int\n"
in.read( (char *) &numbers, 10*sizeof(int));
in.close();
I could write a template function to do this, but I won't know until
run-time what the type will be. Do I have to use a switch to select which
function to use? Or is there a better way?
Brad