|
-
Aug 27th, 2001, 02:48 AM
#1
Convert this from VB to C++
How would I convert this to C++ code?? (I'm using visual C++)
Code:
type header
namefile as string * 16
filesize as long 'size of file
fileoffset as long 'Byte where the file's data starts from
end type
dim head as header
open "C:\file.xxx" for binary access read lock write as #1
get #1, 1, head
dim filedata(head.filesize - 1)
get #1,head.fileoffset,filedata
open "C:\blah.bmp" for binary access write lock write as #2
put #2,1,filedata
close #2
close #1
-
Aug 27th, 2001, 11:13 AM
#2
Try this.
Code:
#include <fstream.h>
struct header {
char namefile[16];
long filesize;
long fileoffset;
};
int main()
{
header head;
ifstream file("C:\\file.xxx", ios::binary);
file.seekg(1);
file.read((char*) &head, sizeof(header));
char *filedata = new char[head.filesize -1];
file.seekg(head.fileoffset);
file.read( filedata, head.fileoffset-1);
file.close();
ofstream newfile("C:\\Blah.bmp", ios::binary);
newfile.seekp(1);
newfile.write( (char*) filedata, head.fileoffset-1);
newfile.close();
delete[] filedata;
return 0;
}
-
Aug 27th, 2001, 06:37 PM
#3
Thanks a lot meg... I had to edit a bit to get it to work.. the reason it didn't work was because you didn't know the file format in the type.. so it's not your fault.. but this is what I did to make it work...
Code:
#include <stdlib.h>
#include <fstream.h>
struct header {
char namefile[16];
long fileoffset; //This was below, I brought it up...
long filesize; // Because file had offset written first.
};
int main()
{
header head;
ifstream file("C:\\file.xxx", ios::binary);
file.seekg(8);
file.read((char*) &head, sizeof(header));
char *filedata = new char[head.filesize];
file.seekg(head.fileoffset);
file.read( filedata, head.filesize); //Changed to head.filesize because offset was the byte at which the data started,
file.close();
cout << head.namefile;
ofstream newfile("C:\\Blah.bmp", ios::binary);
newfile.seekp(1);
newfile.write( (char*) filedata, head.filesize);
newfile.close();
//delete[] filedata;
return 0;
}
ALso I removed the '- 1' from the code, because only VB needs them, C++ is fine with it. THanks again!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|