473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3751
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.d udewrote:
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
2543
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 = cStringIO.StringIO(url_file.read()) ....
4
1672
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 group of objects and their memebers or a few lines of text? and 2) Is there any way to automate object construction? I'm thinking that I can create a vector or something similar to handle the number of people, is there a way for me to write a...
0
2682
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 between those actions into Oracle database into long row field, it doesn´t. Below is some code.
4
7852
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 like to know if I am using the fstream methods properly. (as long as I am cleaning up I might as well do it right). By the way, this is just a bogus example with a structure, values and filename for demonstration purposes. PS-> I have a funny...
8
8923
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 GetChunk and AppendChunk to read and write binary data from the OLE Object field. I am using VBA and DAO for this experiment. The OLE Object field is being used to store Long Binary data.
4
6718
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 code ?? thank you Pedro Leite From Portugal ------------------------------------
10
13401
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 a problem. I am using chunk_split(data) and the base64_encode and base64_decode on the files. I do a select from the database, and then echo the image (with header(Content Type: image/jpeg) and the decoded image displays fine. Yes, I have...
2
1466
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 (int), And answer (nvarchar(255)) and a set of questions on an another table. Questions can have 0 or more answers
5
7948
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, it can open the file. However, when I run Php5 I (now) get this error message: "Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?" This is new. Last time I messed with this, I merely got:
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.