1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include <fstream>
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
typedef struct voxel
{
vector<int> values;
float posx;
float posy;
float posz;
}voxel_t;
int main(void)
{
voxel_t vo;
vo.posx=0.2;
vo.posy=0.6;
vo.posz=0.8;
//si décommenté : double free or corruption
//vo.values.push_back(1);
/*
vo.truc.push_back(1);
vo.truc.push_back(1);
vo.truc.push_back(1);
vo.truc.push_back(1);
vo.truc.push_back(1);
*/
ofstream out("test.bin", ios::out | ios::binary);
out.write((char*)&vo, sizeof(vo));
out.close();
voxel_t vr;
ifstream in("test.bin", ios::in | ios::binary);
//decommanter cette ligne "supprime le double free or corruption" :
//mais retourne mauvaises valeurs
//in.seekg(sizeof(vr));
in.read((char*)&vr, sizeof(vr));
in.close();
cout << "posx : " << vr.posx <<endl;
cout << "posy : " << vr.posy <<endl;
cout << "posz : " << vr.posz <<endl;
/*
for(int i = 0 ; i < vr.truc.size() ; i++)
{
cout << "truc value : " << vr.truc[i] <<endl;
}
*/
return 0;
} |
Partager