reading a complete binary file : Binary File « File « C++






reading a complete binary file

  
#include <iostream>
#include <fstream>
using namespace std;

ifstream::pos_type size;
char * memblock;

int main () {
  ifstream file ("example.txt", ios::in|ios::binary|ios::ate);

  if (file.is_open()){
    size = file.tellg();
    memblock = new char [size];
    file.seekg (0, ios::beg);
    file.read (memblock, size);
    file.close();

    cout << "the complete file content is in memory";

    delete[] memblock;
  }else 
    cout << "Unable to open file";
  return 0;
}
  
    
  








Related examples in the same category

1.Write numbers to a binary file and read them back
2.Binary Files
3.seeks particular person in file
4.binary input and output with integers