On May 12, 12:26 am, "supe...@gmail.com" <supe...@gmail.comwrote:
Quote:
I am having a heck of a time using the ifstream::read() method.
I am using Visual Studio 6.0, and my intelisense indicates that read
has an overload of:
ifstream::read(unsigned char*, int _n)
>
A lot of the code samples I have googled up show this method being
called being called with an unsigned char pointer as well. However
whenever I run my code:
>
#define BYTE unsigned char
...
int size;
BYTE* buffer;
...
std::ifstream inputFile("C:\\test.bin", std::ios::in |
std::ios::binary);
if (inputFile.is_open())
{
inputFile.seekg(0, std::ios::end);
size = inputFile.tellg();
buffer = new BYTE[size];
inputFile.read(buffer, size);
...
>
I get the error:
error C2664: 'read' : cannot convert parameter 1 from 'unsigned char
*' to 'char *' Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
>
If I cast buffer as a char* then my results are incorrect. Can
someone please tell me what I am doing wrong?
inputFile.read( reinterpret_cast<char*>(buffer), size);
gives you the wrong answer ?