Wait, Huh? If you need a variable in a vector to change then... change it... What are you having trouble with?
|
Sorry for the confusion - this does happen already.
Line 7 is just going to read in "sizeof int data type in bytes" it isn't going to read the number of bytes you set nx to. For that you would drop sizeof() and use nx. Also why are we declaring nx as an integer on line 5 then casting it as a char on line 7? You may have a good reason for this but I can't see what it is right now.
|
From the vast amount of things i've read about reading in data from a binary file, this is the method that has worked for me. Perhaps it's by a bit of a fluke, but nevertheless, i get what i want. In regards changing from int to char, it seems to work....... I get the correct value for nx using this method. I've tried putting in int and float in the read statement, but to no avail. Only the char seems to work.
I'd be happy to be instructed otherwise though. I'm only very much beginning to learn how to do all this.
Ok - i see what you do with the resize. Good to know, thanks. Line 9 now becomes:
1 2
|
vector<float> x;
x.resize(nx);
|
However, I don't know how to read in the data, with read, and then the push_back......... You say that Line 7 is wrong(?) - but i get the correct answer. However, it's Line 11 that causes me the problems, unless i don't use the vector array, and just use
Hope this makes more sense.
Thanks for the help so far. Much appreciated.