file length...

From: Steve (steve_at_nospamplease.com)
Date: 01/31/05


Date: Mon, 31 Jan 2005 09:24:59 +0100

Hi,
I'm trying to read a binary file into a buffer:

std::ifstream ifs(fileName,
                  std::ios::in|std::ios::binary);
if (!ifs)
   return;
ifs.seekg(0,std::ios::end);
int len = ifs.tellg();
ifs.seekg(0,std::ios::beg);
char* buf = new char[len];
memcpy(buf,ifs.rdbuf(),len);

However, this is not working as expected since
buf contains not what the original file contains...

I do not want to read character-by-character from
file and the above does not work. So what is the
correct way of doing this "simple" stuff?

Thanks,
Steve



Relevant Pages