How to correctly read an entire binary file?

I wrote this to read a file, but i found the bin it read is not the bin it was...there were some redundant bytes at the end...why is that?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
char* FileToBin(char* lpFileName)
{
	int size;
	char *bin;
	ifstream f(lpFileName,ios::ate|ios::binary);
	if(f.is_open())
	{
	size = f.tellg();
        bin = new char [size];
	f.seekg (0, ios::beg);
	f.read(bin,size);
	f.close();
	return(bin);
	}
	else
	{
		return NULL;
	}

};
there were some redundant bytes at the end...why is that?
how did you determine that?

Note that no 0 is appended when trying to read a string this way. strlen() will not work
Topic archived. No new replies allowed.