I am writing a program that I am trying to learn and save binary
files. This is the page I found as a source: http://www.angelfire.com/country/ald...aryFileIO.html
I have successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
class Map{
int xlen;
int ylen;
int mapTotal;
HWND hwnd;
space * playArea;
grTerrain grTerr;
....
Map::Map(HWND h, const int x, const int y){
xlen = x;
ylen = y;
hwnd = h;
playArea = new space[(xlen * ylen)];
create();
}
void Map::load(std::ifstream& f){
f.seekg (0);
f.read((char*)&mapTotal, sizeof(int));
f.read((char*)&playArea, sizeof(space) * mapTotal);
MessageBox(NULL, "Loading...", "Simulation", MB_OK);
}
void Map::save(std::ofstream& f){
f.seekp (0);
f.write((char*)&mapTotal, sizeof(mapTotal));
f.write((char*)&playArea, sizeof(space));
MessageBox(NULL, "Saving...", "Simulation", MB_OK);
}
case ID_LOAD: {
std::ifstream f("data.bin", ios::in | ios::binary);
board->load(f);
f.close();
InvalidateRect(hwnd,NULL,FALSE);
break;
}
case ID_SAVE:{
std::ofstream f("data.bin", ios::out | ios::binary);
board->save(f);
f.close();
break;
}
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly. 15 2838
JoeC wrote:
I am writing a program that I am trying to learn and save binary
files. This is the page I found as a source: http://www.angelfire.com/country/ald...aryFileIO.html
I have successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
[..]
void Map::load(std::ifstream& f){
f.seekg (0);
f.read((char*)&mapTotal, sizeof(int));
Strange assymetry. You write using 'sizeof(mapTotal)', but you read
using 'sizeof(int)'. Why?
f.read((char*)&playArea, sizeof(space) * mapTotal);
Another strange assymetry (and probably a logical error). You read
'mapTotal' spaces, buy you only wrote one (see below).
MessageBox(NULL, "Loading...", "Simulation", MB_OK);
}
void Map::save(std::ofstream& f){
f.seekp (0);
f.write((char*)&mapTotal, sizeof(mapTotal));
f.write((char*)&playArea, sizeof(space));
If there are 'mapTotal' spaces in your object, why do you only write
one?
>
MessageBox(NULL, "Saving...", "Simulation", MB_OK);
}
[..]
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
And just for the curiousity's sake, did you have a question?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"JoeC" <en*****@yahoo.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
>I am writing a program that I am trying to learn and save binary
files. This is the page I found as a source: http://www.angelfire.com/country/ald...aryFileIO.html
I have successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
class Map{
int xlen;
int ylen;
int mapTotal;
HWND hwnd;
space * playArea;
grTerrain grTerr;
...
Map::Map(HWND h, const int x, const int y){
xlen = x;
ylen = y;
hwnd = h;
playArea = new space[(xlen * ylen)];
create();
}
void Map::load(std::ifstream& f){
f.seekg (0);
f.read((char*)&mapTotal, sizeof(int));
f.read((char*)&playArea, sizeof(space) * mapTotal);
MessageBox(NULL, "Loading...", "Simulation", MB_OK);
}
void Map::save(std::ofstream& f){
f.seekp (0);
f.write((char*)&mapTotal, sizeof(mapTotal));
f.write((char*)&playArea, sizeof(space));
MessageBox(NULL, "Saving...", "Simulation", MB_OK);
}
case ID_LOAD: {
std::ifstream f("data.bin", ios::in | ios::binary);
board->load(f);
f.close();
InvalidateRect(hwnd,NULL,FALSE);
break;
}
case ID_SAVE:{
std::ofstream f("data.bin", ios::out | ios::binary);
board->save(f);
f.close();
break;
}
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
Are you running into a particular problem? Or are you looking to have
someone bug-check all your code? Or are you asking how to verify it saved?
It the latter, then load it back up and compare the loaded data with the
data before the save...Not sure what your exact question is.
On Mar 28, 10:34 am, "JoeC" <enki...@yahoo.comwrote:
I am writing a program that I am trying to learn and save binary
files. This is the page I found as a source:http://www.angelfire.com/country/ald...aryFileIO.html
<snip>
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
I will assume the question is "how do I make sure this is working
correctly?"
Basically, you should figure out what results you are expecting, and
compare those to the actual.
For example, let's say you have an int that is 4 bytes long, with a
value of 0x01020304. If you do a binary dump of the file (e.g., with
the 'od' program under UNIX or loading it into an appropriate binary
viewer in Visual Studio or whatever), you would expect to see the
bytes 01, 02, 03, 04, or possibly 04, 03, 02, 01.
I would recommend creating a small test case with some goofy values
(e.g., 01020304) and confirming, by hand, that it's storing what you
think. I'd be especially careful with the pointer part, as it is
known to be tricky to serialize pointers correctly.
And FYI, there will be some people on this group who tell you that
binary output is the work of the devil, and that text is the
appropriate medium for all exchanges. Since, as I understand it, your
goal is to learn how to do binary output, ignore them.
Michael
On Mar 28, 10:34 am, "JoeC" <enki...@yahoo.comwrote:
I am writing a program that I am trying to learn and save binary
files. This is the page I found as a source:http://www.angelfire.com/country/ald...aryFileIO.html
<snip>
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
I will assume the question is "how do I make sure this is working
correctly?"
Basically, you should figure out what results you are expecting, and
compare those to the actual.
For example, let's say you have an int that is 4 bytes long, with a
value of 0x01020304. If you do a binary dump of the file (e.g., with
the 'od' program under UNIX or loading it into an appropriate binary
viewer in Visual Studio or whatever), you would expect to see the
bytes 01, 02, 03, 04, or possibly 04, 03, 02, 01.
I would recommend creating a small test case with some goofy values
(e.g., 01020304) and confirming, by hand, that it's storing what you
think. I'd be especially careful with the pointer part, as it is
known to be tricky to serialize pointers correctly.
And FYI, there will be some people on this group who tell you that
binary output is the work of the devil, and that text is the
appropriate medium for all exchanges. Since, as I understand it, your
goal is to learn how to do binary output, ignore them.
Michael
On Mar 28, 7:34 pm, "JoeC" <enki...@yahoo.comwrote:
I am writing a program that I am trying to learn and save binary
files.
In what format?
All data has some format. Binary is not, in itself, a format;
there are many different binary formats (e.g. XDR, BER, etc.).
Until you specify the format, you can't really talk about how to
do IO.
This is the page I found as a source:http://www.angelfire.com/country/ald...aryFileIO.html
A quick check shows the page to present a curious mishmash of
C++ and Posix, without specifying which is which. And the C++
seems out of date (e.g. <fstream.h>), although not much has
changed at the level the page addresses. I'm not sure I'd
recommend it (although I've definitly seen a lot worse).
I have successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
An array of pointers? Generally speaking, there is no possible
way to format a pointer so that it can be reread successfully.
Depending on what the pointer is being used for, you either have
to replace it with some other type of identifier, or format what
it points to. (In your case, doubtlessly the latter.)
class Map{
int xlen;
int ylen;
int mapTotal;
HWND hwnd;
Curious as to what HWND might be. (Not that it really matters.)
space * playArea;
grTerrain grTerr;
...
Map::Map(HWND h, const int x, const int y){
xlen = x;
ylen = y;
hwnd = h;
playArea = new space[(xlen * ylen)];
create();
}
void Map::load(std::ifstream& f){
f.seekg (0);
f.read((char*)&mapTotal, sizeof(int));
f.read((char*)&playArea, sizeof(space) * mapTotal);
MessageBox(NULL, "Loading...", "Simulation", MB_OK);
}
void Map::save(std::ofstream& f){
f.seekp (0);
f.write((char*)&mapTotal, sizeof(mapTotal));
f.write((char*)&playArea, sizeof(space));
MessageBox(NULL, "Saving...", "Simulation", MB_OK);
}
Two immediate problems:
-- You haven't defined a format, so you're getting some random
format decided by the compiler. As long as you reread with
exactly the same executable (on the same machine, compiled
with the same compiler, same version and with the same
options), reading and writing basic types (e.g. int, etc.)
will probably work, but that's about it. For anything else,
you need to define a format, convert to it on output, and
from it on input.
-- You're trying to write and read a pointer. That is simply
impossible. You must read and write what it points to.
Note too that the need for casts here should make you very, very
suspicious that you're doing something wrong. (But it's not an
absolute---for various reasons, I generally format binary into
a buffer of unsigned char, but still use basic_[io]stream<char>,
rather than basic_[io]stream<unsigned char>, so I usually need
the cast as well.)
The real problem is that you haven't even thought about the
format. What do you actually want in the file. Described down
to the last byte. (Note that this first step is really no
different than what you'd do for text IO. The differences come
later, because there is a good deal of support for implementing
text formats, i.e. the << and >operators, and none for
binary.)
case ID_LOAD: {
std::ifstream f("data.bin", ios::in | ios::binary);
board->load(f);
f.close();
InvalidateRect(hwnd,NULL,FALSE);
break;
}
case ID_SAVE:{
std::ofstream f("data.bin", ios::out | ios::binary);
board->save(f);
f.close();
break;
}
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
That's one reason why text files are generally preferred. It's
a lot easier to debug a text file, since you can look at it with
just about any editor. Another reason to prefer text files is
that a lot of the work has already been done for you. On the
other hand, formatting a binary file generally takes less CPU
(not usually an issue, but sometimes), and depending on the
data, a binary file might be smaller (but I've also seen cases
of the opposite); a text file can generally be compressed to
make it smaller than a binary file, but then reading and writing
it take a lot more CPU.
Anyway, the first thing to do is to sit down and make a sort of
a schema as to what you want in the file, where. Precisely, not
just something vague.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Mar 28, 12:57 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
JoeC wrote:
I am writing a program that I am trying to learn and save binary
files. This is the page I found as a source: http://www.angelfire.com/country/ald...aryFileIO.html
I have successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
[..]
void Map::load(std::ifstream& f){
f.seekg (0);
f.read((char*)&mapTotal, sizeof(int));
Strange assymetry. You write using 'sizeof(mapTotal)', but you read
using 'sizeof(int)'. Why?
f.read((char*)&playArea, sizeof(space) * mapTotal);
Another strange assymetry (and probably a logical error). You read
'mapTotal' spaces, buy you only wrote one (see below).
MessageBox(NULL, "Loading...", "Simulation", MB_OK);
}
void Map::save(std::ofstream& f){
f.seekp (0);
f.write((char*)&mapTotal, sizeof(mapTotal));
f.write((char*)&playArea, sizeof(space));
If there are 'mapTotal' spaces in your object, why do you only write
one?
MessageBox(NULL, "Saving...", "Simulation", MB_OK);
}
[..]
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
And just for the curiousity's sake, did you have a question?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks, I will look at what you wrote and make some corrections. I
realized that I have pointers in the spaces so each space will have to
save themselves. I still have some work to do, I don't really
understand how to save binary files. I know how to do text files and
I am just trying to save data in a bin file.
On Mar 28, 2:27 pm, "Christopher Pisz" <some...@somewhere.netwrote:
"JoeC" <enki...@yahoo.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
I am writing a program that I am trying to learn and save binary
files. This is the page I found as a source: http://www.angelfire.com/country/ald...aryFileIO.html
I have successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
class Map{
int xlen;
int ylen;
int mapTotal;
HWND hwnd;
space * playArea;
grTerrain grTerr;
...
Map::Map(HWND h, const int x, const int y){
xlen = x;
ylen = y;
hwnd = h;
playArea = new space[(xlen * ylen)];
create();
}
void Map::load(std::ifstream& f){
f.seekg (0);
f.read((char*)&mapTotal, sizeof(int));
f.read((char*)&playArea, sizeof(space) * mapTotal);
MessageBox(NULL, "Loading...", "Simulation", MB_OK);
}
void Map::save(std::ofstream& f){
f.seekp (0);
f.write((char*)&mapTotal, sizeof(mapTotal));
f.write((char*)&playArea, sizeof(space));
MessageBox(NULL, "Saving...", "Simulation", MB_OK);
}
case ID_LOAD: {
std::ifstream f("data.bin", ios::in | ios::binary);
board->load(f);
f.close();
InvalidateRect(hwnd,NULL,FALSE);
break;
}
case ID_SAVE:{
std::ofstream f("data.bin", ios::out | ios::binary);
board->save(f);
f.close();
break;
}
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
Are you running into a particular problem? Or are you looking to have
someone bug-check all your code? Or are you asking how to verify it saved?
It the latter, then load it back up and compare the loaded data with the
data before the save...Not sure what your exact question is.
First, am I doing it right, then how do I know of it saved?
On Mar 28, 4:14 pm, "Michael" <mchlg...@aol.comwrote:
On Mar 28, 10:34 am, "JoeC" <enki...@yahoo.comwrote:I am writing a program that I am trying to learn and save binary
files. This is the page I found as a source:http://www.angelfire.com/country/ald...aryFileIO.html
<snip>
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
I will assume the question is "how do I make sure this is working
correctly?"
Basically, you should figure out what results you are expecting, and
compare those to the actual.
For example, let's say you have an int that is 4 bytes long, with a
value of 0x01020304. If you do a binary dump of the file (e.g., with
the 'od' program under UNIX or loading it into an appropriate binary
viewer in Visual Studio or whatever), you would expect to see the
bytes 01, 02, 03, 04, or possibly 04, 03, 02, 01.
I would recommend creating a small test case with some goofy values
(e.g., 01020304) and confirming, by hand, that it's storing what you
think. I'd be especially careful with the pointer part, as it is
known to be tricky to serialize pointers correctly.
And FYI, there will be some people on this group who tell you that
binary output is the work of the devil, and that text is the
appropriate medium for all exchanges. Since, as I understand it, your
goal is to learn how to do binary output, ignore them.
Michael
I assume that I have to save the piece of data then load it back up
the same way I saved it. I have been working on my code and trying to
save my data correctly.
On Mar 29, 7:18 am, "James Kanze" <james.ka...@gmail.comwrote:
On Mar 28, 7:34 pm, "JoeC" <enki...@yahoo.comwrote:
I am writing a program that I am trying to learn and save binary
files.
In what format?
All data has some format. Binary is not, in itself, a format;
there are many different binary formats (e.g. XDR, BER, etc.).
Until you specify the format, you can't really talk about how to
do IO.
This is the page I found as a source:http://www.angelfire.com/country/ald...aryFileIO.html
A quick check shows the page to present a curious mishmash of
C++ and Posix, without specifying which is which. And the C++
seems out of date (e.g. <fstream.h>), although not much has
changed at the level the page addresses. I'm not sure I'd
recommend it (although I've definitly seen a lot worse).
I have successfully created and used txt files.
I am trying to save then load in an array of pointers to objects:
An array of pointers? Generally speaking, there is no possible
way to format a pointer so that it can be reread successfully.
Depending on what the pointer is being used for, you either have
to replace it with some other type of identifier, or format what
it points to. (In your case, doubtlessly the latter.)
class Map{
int xlen;
int ylen;
int mapTotal;
HWND hwnd;
Curious as to what HWND might be. (Not that it really matters.)
space * playArea;
grTerrain grTerr;
...
Map::Map(HWND h, const int x, const int y){
xlen = x;
ylen = y;
hwnd = h;
playArea = new space[(xlen * ylen)];
create();
}
void Map::load(std::ifstream& f){
f.seekg (0);
f.read((char*)&mapTotal, sizeof(int));
f.read((char*)&playArea, sizeof(space) * mapTotal);
MessageBox(NULL, "Loading...", "Simulation", MB_OK);
}
void Map::save(std::ofstream& f){
f.seekp (0);
f.write((char*)&mapTotal, sizeof(mapTotal));
f.write((char*)&playArea, sizeof(space));
MessageBox(NULL, "Saving...", "Simulation", MB_OK);
}
Two immediate problems:
-- You haven't defined a format, so you're getting some random
format decided by the compiler. As long as you reread with
exactly the same executable (on the same machine, compiled
with the same compiler, same version and with the same
options), reading and writing basic types (e.g. int, etc.)
will probably work, but that's about it. For anything else,
you need to define a format, convert to it on output, and
from it on input.
-- You're trying to write and read a pointer. That is simply
impossible. You must read and write what it points to.
Note too that the need for casts here should make you very, very
suspicious that you're doing something wrong. (But it's not an
absolute---for various reasons, I generally format binary into
a buffer of unsigned char, but still use basic_[io]stream<char>,
rather than basic_[io]stream<unsigned char>, so I usually need
the cast as well.)
The real problem is that you haven't even thought about the
format. What do you actually want in the file. Described down
to the last byte. (Note that this first step is really no
different than what you'd do for text IO. The differences come
later, because there is a good deal of support for implementing
text formats, i.e. the << and >operators, and none for
binary.)
case ID_LOAD: {
std::ifstream f("data.bin", ios::in | ios::binary);
board->load(f);
f.close();
InvalidateRect(hwnd,NULL,FALSE);
break;
}
case ID_SAVE:{
std::ofstream f("data.bin", ios::out | ios::binary);
board->save(f);
f.close();
break;
}
I posted the parts of the program that apply to the saving and
loading. The program does save and creates a bin files 53kb so it
seems like the data is saving but unlike txt files, it is hard to
verify if the informations saved correctly.
That's one reason why text files are generally preferred. It's
a lot easier to debug a text file, since you can look at it with
just about any editor. Another reason to prefer text files is
that a lot of the work has already been done for you. On the
other hand, formatting a binary file generally takes less CPU
(not usually an issue, but sometimes), and depending on the
data, a binary file might be smaller (but I've also seen cases
of the opposite); a text file can generally be compressed to
make it smaller than a binary file, but then reading and writing
it take a lot more CPU.
Anyway, the first thing to do is to sit down and make a sort of
a schema as to what you want in the file, where. Precisely, not
just something vague.
--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Thanks, I have worked with text files and got them to work. I realize
that I am learning to do binary files on a complex program and I
should get it to work and understand what I am doing with a simpler
format. It might be too dificult and above my sill to save the
program I am doing in a file.
JoeC wrote:
On Mar 28, 2:27 pm, "Christopher Pisz" <some...@somewhere.netwrote:
>"JoeC" <enki...@yahoo.comwrote in message [..] Are you running into a particular problem? Or are you looking to have someone bug-check all your code? Or are you asking how to verify it saved? It the latter, then load it back up and compare the loaded data with the data before the save...Not sure what your exact question is.
First, am I doing it right, then how do I know of it saved?
Unless you have a different program that can read what you saved and
confirm, a round-trip is usually a way to go. Read back what you saved
in another run and see if the information is valid.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Mar 30, 8:08 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
JoeC wrote:
On Mar 28, 2:27 pm, "Christopher Pisz" <some...@somewhere.netwrote:
"JoeC" <enki...@yahoo.comwrote in message
[..]
Are you running into a particular problem? Or are you looking to have
someone bug-check all your code? Or are you asking how to verify it
saved? It the latter, then load it back up and compare the loaded
data with the data before the save...Not sure what your exact
question is.
First, am I doing it right, then how do I know of it saved?
Unless you have a different program that can read what you saved and
confirm, a round-trip is usually a way to go. Read back what you saved
in another run and see if the information is valid.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I created another program in which I was able to save and read binary
data. I also worked on the program I am trying to create and it
doesn't work. But I will still if I can find the problems myself.
JoeC wrote:
On Mar 30, 8:08 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>JoeC wrote:
>>On Mar 28, 2:27 pm, "Christopher Pisz" <some...@somewhere.net> wrote: "JoeC" <enki...@yahoo.comwrote in message [..] Are you running into a particular problem? Or are you looking to have someone bug-check all your code? Or are you asking how to verify it saved? It the latter, then load it back up and compare the loaded data with the data before the save...Not sure what your exact question is.
>>First, am I doing it right, then how do I know of it saved?
Unless you have a different program that can read what you saved and confirm, a round-trip is usually a way to go. Read back what you saved in another run and see if the information is valid.
V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
I created another program in which I was able to save and read binary
data. I also worked on the program I am trying to create and it
doesn't work. But I will still if I can find the problems myself.
By the other program I meant not written by you. Example, if you are
to write an raster image file, like a JFIF or a PNG, you can pretty
much use any viewer to see if what you wrote can be read in. Or, in
case of a generic binary file, you could use a hex editor to see what
bytes you wrote look like and compare them with your specification.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Apr 1, 8:14 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
JoeC wrote:
On Mar 30, 8:08 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
JoeC wrote: On Mar 28, 2:27 pm, "Christopher Pisz" <some...@somewhere.net> wrote: "JoeC" <enki...@yahoo.comwrote in message [..] Are you running into a particular problem? Or are you looking to have someone bug-check all your code? Or are you asking how to verify it saved? It the latter, then load it back up and compare the loaded data with the data before the save...Not sure what your exact question is.
>First, am I doing it right, then how do I know of it saved?
Unless you have a different program that can read what you saved and
confirm, a round-trip is usually a way to go. Read back what you
saved in another run and see if the information is valid.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I created another program in which I was able to save and read binary
data. I also worked on the program I am trying to create and it
doesn't work. But I will still if I can find the problems myself.
By the other program I meant not written by you. Example, if you are
to write an raster image file, like a JFIF or a PNG, you can pretty
much use any viewer to see if what you wrote can be read in. Or, in
case of a generic binary file, you could use a hex editor to see what
bytes you wrote look like and compare them with your specification.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I am getting close. I can save many parts of my map but the graphics
are the challenge. I got this to work:
void space::load(std::ifstream& f){
int s = colors.size();
bool t;
woods = 0;
gr->load(f);
f.read((char*)&loc, sizeof(coord));
f.read((char*)&quality,sizeof(int));
f.read((char*)&terrain,sizeof(int));
f.read((char*)&s, sizeof(int));
for(int lp = 0; lp != s; lp++){
f.read((char*)&colors[lp], sizeof(DWORD));
}
f.read((char*)&t, sizeof(bool));
//if(t){f.read((char*)&woods, sizeof(forrest));}
}
void space::save(std::ofstream& f){
bool t;
int size = colors.size();
gr->save(f);
f.write((char*)&loc, sizeof(coord));
f.write((char*)&quality,sizeof(int));
f.write((char*)&terrain,sizeof(int));
f.write((char*)&size, sizeof(int));
for(int lp = 0; lp != colors.size(); lp++){
f.write((char*)&colors[lp], sizeof(DWORD));
}
if(woods){t=true;} else {t=false;}
f.write((char*)&t, sizeof(bool));
//if(t){f.write((char*)woods, sizeof (forrest));}
}
But I am havign trouble loading in the objects that have graphics like
gr which is a binary graphic that I crated and woods which holds a
bitmap graphic. Here is what I have for loading the binary gr
graphic:
void graphics::load(std::ifstream& f){
bitData.clear();
for(int lp = 0; lp != len; lp++){
f.read((char*)&bitData[lp],sizeof(BYTE));
}
}
void graphics::save(std::ofstream& f){
for(int lp = 0; lp != len; lp++){
f.write((char*)&bitData[lp],sizeof(BYTE));
}
}
What I get is the current terrain graphics on a saved map.
JoeC wrote:
[..] I am havign trouble loading in the objects that have graphics like
gr which is a binary graphic that I crated and woods which holds a
bitmap graphic. Here is what I have for loading the binary gr
graphic:
void graphics::load(std::ifstream& f){
bitData.clear();
Since I have no idea what 'bitData' is, I can't say whether calling
'clear' is the right thing to do here. It is suspect, though. If
'bitData' is a standard container, 'clear' removes all elements, and
then it has no elements. Perhaps you need to pre-allocate them.
for(int lp = 0; lp != len; lp++){
f.read((char*)&bitData[lp],sizeof(BYTE));
The use of the indexing operator suggests that either 'bitData' is
a vector (which would mean undefined behaviour since it contains no
elements after 'clear') or a map. If the latter, you might be OK,
but who knows...
}
}
void graphics::save(std::ofstream& f){
for(int lp = 0; lp != len; lp++){
f.write((char*)&bitData[lp],sizeof(BYTE));
}
}
What I get is the current terrain graphics on a saved map.
Which would probably indicate that you don't read anything. So,
check the functionality of your 'load' routine carefully.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Apr 3, 8:22 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
JoeC wrote:
[..] I am havign trouble loading in the objects that have graphics like
gr which is a binary graphic that I crated and woods which holds a
bitmap graphic. Here is what I have for loading the binary gr
graphic:
void graphics::load(std::ifstream& f){
bitData.clear();
Since I have no idea what 'bitData' is, I can't say whether calling
'clear' is the right thing to do here. It is suspect, though. If
'bitData' is a standard container, 'clear' removes all elements, and
then it has no elements. Perhaps you need to pre-allocate them.
Sorry Bit data is a vector of BYTE type.
for(int lp = 0; lp != len; lp++){
f.read((char*)&bitData[lp],sizeof(BYTE));
The use of the indexing operator suggests that either 'bitData' is
a vector (which would mean undefined behaviour since it contains no
elements after 'clear') or a map. If the latter, you might be OK,
but who knows...
}
}
void graphics::save(std::ofstream& f){
for(int lp = 0; lp != len; lp++){
f.write((char*)&bitData[lp],sizeof(BYTE));
}
}
What I get is the current terrain graphics on a saved map.
Which would probably indicate that you don't read anything. So,
check the functionality of your 'load' routine carefully.
That is my load function. It is possible that I am not loading
anything because the old graphics are still there after I load in the
map. I get the new map with the old graphic symbols that is the
graphics that were created when I created the map from the current
execution stay although I loaded in saved data. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Eric |
last post by:
Assume that disk space is not an issue
(the files will be small < 5k in general for the purpose of storing
preferences)
Assume that transportation to another OS may never occur.
Are there...
|
by: wwj |
last post by:
void main()
{
char* p="Hello";
printf("%s",p);
*p='w';
printf("%s",p);
}
|
by: Ching-Lung |
last post by:
Hi all,
I try to create a tool to check the delta (diff) of 2
binaries and create the delta binary. I use binary
formatter (serialization) to create the delta binary. It
works fine but the...
|
by: dagecko |
last post by:
Hi
I would like to know how to detect if a file is binary or not.
It's important for me but I don't know where to start.
Ty
|
by: joelagnel |
last post by:
hi friends,
i've been having this confusion for about a year, i want to know the
exact difference between text and binary files.
using the fwrite function in c, i wrote 2 bytes of integers in...
|
by: vim |
last post by:
hello everybody
Plz tell the differance between binary file and ascii
file...............
Thanks
in advance
vim
|
by: nicolasg |
last post by:
Hi,
I'm trying to open a file (any file) in binary mode and save it inside
a new text file.
After that I want to read the source from the text file and save it
back to the disk with its...
|
by: masood.iqbal |
last post by:
Hi,
Kindly excuse my novice question. In all the literature on ifstream
that I have seen, nowhere have I read what happens if you try to read
a binary file using the ">>" operator. I ran into...
|
by: deepakvsoni |
last post by:
are binary files portable?
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
| |