Hey guys,
I am writing a C++ program with the help of dynamic allocation of a character array. The size of the array depends on the size of file read. However, when I checked the size of allocated array, it is always 4! So, is there any limit on this kind of allocations? Or is there any problem about my program? Thanks a lot for your help!
ps. I need to read in JPG or BMP files (max. 400KB), is this algorithm appropriate indeed?
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main() {
int bufflen;
char* buffer;
..............
ifstream filein ("buffer.txt", ios::in); // open a file to read in
if (filein.is_open() != TRUE){
cout << "ERROR: Fail to open data\n";
exit(1);
}
filein.seekg (0, ios::end); // get length of file
bufflen = filein.tellg(); // int, value should be over 30000
buffer = new char [bufflen]; // allocate character array dynamically
filein.seekg (0, ios::beg);
filein.get (buffer, sizeof(buffer)); // read data into my allocated array
..............
delete[] buffer;
return 0;
}