Hello...
I am trying to get any file such as images, word documents, etc... and save it in a buffer inside my program. The issue is that when I create a file with another name but with the same extension as the file in the buffer, the file doesn't work. It's corrupted. I am trying to get any file and save it in a buffer.
This is my code:
ofstream out("image2.jpg");
ifstream in("image.jpg");
if(!out || !in)
{
cout<<"ERROR"<<endl;
system("pause");
return 0;
}
char *buffer;
int size = 0;
char c;
in.seekg(0,ios::end);
size = in.tellg();
in.seekg(0,ios::beg);
buffer = new char[size];
strcpy(buffer,"");
for(int x=0;x<=size;x++)
{
if(in.good())
{
c = in.get();
buffer[x] = c;
}
}
out.write(buffer,size);
out.close();
in.close();
_________________________________________________________________
Hotmail® has ever-growing storage! Don’t worry about storage limits.
http://windowslive.com/Tutorial/Hotmail/Storage?ocid=TXT_TAGLM_WL_HM_Tutorial_Storage_062009 |