I have got file with vector of :
typedef struct {
float fX; ///< position X
float fY; ///< position Y
int iSize; ///< Size of point
} structParams;
but I would like to read it to vector of nearly the same struct but without iSize
typedef struct {
float fX; ///< position X eq. structParams.fX
float fY; ///< position Y eq. structParams.fY
} structPositionParams;
Can I do this in similar way to
ifstream inStr("file.dat");
vector<structPositionParams> oVector;
oVector.(numOfElements);
inStr.read((char*)&oVector[0], sizeof(structPositionParams) * numOfElements);
inStr.close();
You’ve got to utilize the stride of the data. Since the standard library doesn’t support reading strided data in any way, either you read the whole file, and then run a for loop creating objects from that data, or do whole reading in a for loop, skipping
sizeof(int)after each object.