Skip to main content
GameDev.net gamedev.net
🔒 Locked

Binary-Access Data Types

Started by Gaiiden Oct 10, 2000 at 6:07 PM 3 replies 650+ views
Original Post
Gaiiden
Gaiiden
hey, I''m exploring Binary Access with files, I found an article here on GameDev. I''m just wondering - when you read the data in, what to you put it in? My coworker was thinking of using a char array, but I''m not too sure that will work. I was thinking of using the BYTE data type. Can anyone give some help? Thanks. ============================== \\// live long and prosper; \||/ die short and rot. ==============================
Drew Sikora
Executive Producer
GameDev.net
djsteffey
djsteffey
you use binary files like this
    
ofstream out;
out.open("filename", ios::binary); // i think that is the right

int x = 5;
out.write((char*)&x, sizeof(int));
out.close();


// now to read it in

ifstream in;
in.open("filename", ios::binary);
int x;
in.read((char*)&x, sizeof(int));
in.close();

now x will be equal to 5
you can replace the int with any data type you want
it could even be a struct that you create


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Shannon Barber
Shannon Barber
did you say coworker?

a BYTE is an unsigned char

sometimes you use void*, sometimes char* or BYTE*, you need to know how to cast.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Muzzafarath
Muzzafarath
quote:
Original post by Gaiiden

when you read the data in, what to you put it in?



You can put it in whatever you like - a float, an int, a struct, whatever.
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Gaiiden
Gaiiden
cool. Thanks guys. makes my life easier....

==============================
\\// live long and prosper; \||/ die short and rot.
==============================
Drew Sikora
Executive Producer
GameDev.net

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.