I'm trying to get the contents of a binary file into a char array, my read function is in main.cpp, in the header file is referenced as char fileio(char * bufferZ) , and is called in another .cpp file.
The problem is , the code in the function cant get the length of files that are larger than about 10 KB.The length gets to 0.

The read file function is:

char fileio(char * bufferZ){

  // get file size method 1      
  long begin,end;
  ifstream myfile ("1.im");
  begin = myfile.tellg();
  myfile.seekg (0, ios::end);
  end = myfile.tellg();

   ifstream is;
   int length;
   is.open ("1.im", ios::binary );

   // get file size method 2
  is.seekg (0, ios::end);
  length = is.tellg();
  is.seekg (0, ios::beg);

  //is.read (bufferZ,length);
  is.read (bufferZ, (end-begin)  );


I'm using this in a winapi program.

I don't know what compiler you are using, but this works (your second attempt) with vc++ 2012 Express. Maybe the problem is caused by something else in your program.

#include <iostream>
#include <fstream>
int main()
    long length;
    std::ifstream is("l.2");
    is.seekg (0, std::ios::end);
  length = is.tellg();
  std::cout << length << '\n';


Thank you, yes the problem was from somewhere else.