I asked a similar question some weeks ago, but I got stuck, and didn’t really know if I didn’t make any other mistakes.
I can relatively clearly tell what I am fighting with now.
I am trying re-write a VB6 function in C++.
The difficult line is this one:
vector<int>vIntegerValues;
vIntegerValues.resize(iCountIntegers);
fseek(iReadFile, uFromBytePos * sizeof(int), SEEK_CUR);
size_t readElements = fread(&vIntegerValues[0], sizeof(int), iCountIntegers, iReadFile);
My VB6 version is this:
Dim vIntegerValues() As Integer
ReDim vIntegerValues(0 To iCountIntegers)
Get #iReadFile, uFromBytePos, vIntegerValues()
However the C++ function fills up the integer vector with data that is not as expected.
For example in VB6 the first values are:
0,0,2,2,0,-2,0,-2,0,2,0,0,-2,
And in C++ the first values are
131074, -131072, -131072, 131072, 0, 65534
Can somebody help when he sees where I go wrong?
Thank you very much.
ps: I don’t know in advance what the size of the vector vIntegerValues will be, so please do not suggest anything with a fixed vector. This is where I would get stuck.
Your VB6
Integers are 16-bit words. Useint16_t(orshort inton some platforms, including yours 🙂 to get the same thing in C++.