472,799 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

Loading and Saving Binary Data

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::ofstream f("box.bin", ios::out | 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::ofstream& f){
for(int lp = 0; lp != size; lp++){
f.write((char*)&bitData[lp], sizeof(BYTE));
}
}
Nov 20 '07 #1
2 3680
JoeC wrote:
I have successfully saved and re-loaded binary data but I am having
some trouble with some data:
That's nice. Would you mind being a bit more specific? What trouble
are you having? What are you expecting?

Post a minimal *COMPILABLE* example that exhibits the behavior in
question. Note that your fragment below is not a compilable example.
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:
BYTE undefined.
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 undefined.
graphics gr(bits);

std::ofstream f("box.bin", ios::out | 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 and size undefined.
bitData.clear();
for(int lp = 0; lp != size; lp++){
f.read((char*)&bitData[lp],sizeof(BYTE));
no error checking on istream::read().
}
}
void graphics::save(std::ofstream& f){
see comments for load.
for(int lp = 0; lp != size; lp++){
f.write((char*)&bitData[lp], sizeof(BYTE));
}
}
Nov 20 '07 #2
On Nov 19, 10:41 pm, red floyd <no.s...@here.dudewrote:
JoeC wrote:
I have successfully saved and re-loaded binary data but I am having
some trouble with some data:

That's nice. Would you mind being a bit more specific? What trouble
are you having? What are you expecting?

Post a minimal *COMPILABLE* example that exhibits the behavior in
question. Note that your fragment below is not a compilable example.
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:

BYTE undefined.
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 undefined.
graphics gr(bits);
std::ofstream f("box.bin", ios::out | 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 and size undefined.
bitData.clear();
for(int lp = 0; lp != size; lp++){
f.read((char*)&bitData[lp],sizeof(BYTE));

no error checking on istream::read().
}
}
void graphics::save(std::ofstream& f){

see comments for load.
for(int lp = 0; lp != size; lp++){
f.write((char*)&bitData[lp], sizeof(BYTE));
}
}


The program compiles and runs. It seems to save data, it create the
file and seems to be about the right size but I can't seem to get the
data to load. That is I save the graphics then when I load it it does
not display the saved shape. This is the only relieve5t cone and it
does not seem to be wrong it just doesn't load.
Nov 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: rixdelei | last post by:
Hi there! Tried successfully downloading data into memory from internet using the urllib module like this: .... import urllib import cStringIO url_file = urllib.urlopen(url) img =...
4
by: Jerivix Entadi | last post by:
I'm attempting to create an application to work with a fluid database of people. I'm doing this in a command line, text-based manner. I need to know two things: 1) How do I save data, perhaps a...
0
by: Tommy Christian | last post by:
Hi! Anyone who knows about saving serialized data to database, coz I have a problem with that. If I just serialize my session data and then deserialize it, it works. But when I save it...
4
by: adamrobillard | last post by:
Hi, I have always used fopen and FILE* to load and save structures to file. I am trying to convert all the older code to use proper C++ calls... the following code works properly but I would...
8
by: Mark | last post by:
Hello. I am attempting to write binary data from a file to an OLE Object field, and then write the file back out from the database. I am reading and writing the files in binary mode, and using...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
10
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without...
2
by: Vili | last post by:
Hi all I am having problems with creating an functional questionnaire with asp.net 2.0 and MSSQL 2005 database. I have a table with field id (key & auto int), clientId (int), QuestionId...
5
by: Chuck Anderson | last post by:
I run Apache 2.0.55, and Php (both 4.4.1 and 5.2.5) on my home PC (Windows XP). One of the scripts that I run daily needs to access a secure URL (https://..............). When I am running Php4,...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.