473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3729
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.