Using dynamic allocation:
Code:
int main(void)
{
long size;
char *filename = "filename1.txt";
char *out_filename = "filename2.txt";
ifstream openFile;
openFile.open(filename, ios::in | ios::binary);
if (!openFile)
{
cout << "Unable to open file:" << filename << endl;
return 0;
}
openFile.seekg(0, ios::end);
size = openFile.tellg();
cout << "size of file " << filename << ":" << size << endl;
char *temp;
temp = new char[size];
openFile.read((char *) temp, size);
ofstream out(out_filename,ios::binary);
out.write((char *) temp, size);
openFile.close();
out.close();
delete []temp;
return 0;
}
Also, you can declare a static array:
char temp[2700];
cout << "sizeof temp:" << sizeof(temp) << endl;
sizeof() here will be 2700. However if temp is passed to a function, then sizeof() will be the size of a pointer.