J
JoeC
I have successfully saved and re-loaded binary data but I am having
some trouble with some data:
I wrote a binary graphics object and it takes data in a BYTE form.
Here is the data I have and how I save then load it:
static BYTE bits [] =
{0xff,0xff, 0x00,0x00, 0x7f,0xfe, 0x7f,0xfe,
0x7f,0xfe, 0x7f,0xfe, 0x7f,0xfe, 0x7e,0x7e,
0x7e,0x7e, 0x7f,0xfe, 0x7f,0xfe, 0x7f,0xfe,
0x7f,0xfe, 0x7f,0xfe, 0x7f,0xfe, 0x00,0x00};
graphics gr(bits);
std:fstream f("box.bin", ios:ut | ios::binary);
gr.save(f);
f.close();
std::ifstream f("box.bin", ios::in | ios::binary);
gr.load(f);
f.close();
void graphics::load(std::ifstream& f){
bitData.clear();
for(int lp = 0; lp != size; lp++){
f.read((char*)&bitData[lp],sizeof(BYTE));
}
}
void graphics::save(std:fstream& f){
for(int lp = 0; lp != size; lp++){
f.write((char*)&bitData[lp], sizeof(BYTE));
}
}
some trouble with some data:
I wrote a binary graphics object and it takes data in a BYTE form.
Here is the data I have and how I save then load it:
static BYTE bits [] =
{0xff,0xff, 0x00,0x00, 0x7f,0xfe, 0x7f,0xfe,
0x7f,0xfe, 0x7f,0xfe, 0x7f,0xfe, 0x7e,0x7e,
0x7e,0x7e, 0x7f,0xfe, 0x7f,0xfe, 0x7f,0xfe,
0x7f,0xfe, 0x7f,0xfe, 0x7f,0xfe, 0x00,0x00};
graphics gr(bits);
std:fstream f("box.bin", ios:ut | ios::binary);
gr.save(f);
f.close();
std::ifstream f("box.bin", ios::in | ios::binary);
gr.load(f);
f.close();
void graphics::load(std::ifstream& f){
bitData.clear();
for(int lp = 0; lp != size; lp++){
f.read((char*)&bitData[lp],sizeof(BYTE));
}
}
void graphics::save(std:fstream& f){
for(int lp = 0; lp != size; lp++){
f.write((char*)&bitData[lp], sizeof(BYTE));
}
}