Jump to content
  • Advertisement
Sign in to follow this  
ov3r_dr1v3

Reading Binary files...

This topic is 3937 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey... I'm attempting to read in a binary file (.3ds file) and extract the data contained in it. This is the first time I've used binary file so I've got a little bit stuck and was wondering if anyone could help me. this is what i have so far...basically I've just used ifstream to read in the first 2 bytes of the binary file in buffer.
#include <iostream>
#include <fstream>
using namespace std;

unsigned short chunk_id;
unsigned int chunk_length;

char buffer[2];

int main ()
{
	ifstream file ("test.3ds", ios::in|ios::binary);
	if(file.read(buffer, 2))
	{
		cout << "first 2 bytes of file read in" << endl;
	}

	else
	{
		cout << "cannot open file" << endl;
	}

	return 0;
}

what I want to do is to check what the hexadecimal value read into the buffer was. If i just compare them, for example if(buffer = 0x4D4D) then i get an error saying cannot convert from int to char. If anyone could help me i'd be very grateful thanks

Share this post


Link to post
Share on other sites
Advertisement
You have to test the data where the buffer is pointing to, not the buffer itself (which is an address); and don't confuse = (assignment) and == (test).

-> if (buffer[0] == 0x4D && buffer[1] == 0x4D)

Edit: I might suggest you to google for an already implemented 3ds loader, but the code you will find might be hard to understand.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!