N
news.hku.hk
i am writing a small program to get a binary file, but i really don't know
how to convert the strings in a buffer to the required binary bytes, most
probably i can't read each bytes in buffer separately.........
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <iomanip>
using namespace std;
int main() {
ofstream out;
out.open("test.bin", ios::binary|ios:ut);
if (!out) {
cout << "Cannot open test.bin for output";
return 1;
}
char buffer[50]
={"7f 45 4c 46 01 02 01 00 00 00 2f 75 73 72 2f 6c 12 13 7f 82"};
out << hex << buffer; // i think the problem is
here
out.close();
cout << "test.bin created" << endl;
return 0;
}
The expected screen output of od -t x1 test.bin is:
ELF /usr/l
i really has no idea about it.......please help
how to convert the strings in a buffer to the required binary bytes, most
probably i can't read each bytes in buffer separately.........
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <iomanip>
using namespace std;
int main() {
ofstream out;
out.open("test.bin", ios::binary|ios:ut);
if (!out) {
cout << "Cannot open test.bin for output";
return 1;
}
char buffer[50]
={"7f 45 4c 46 01 02 01 00 00 00 2f 75 73 72 2f 6c 12 13 7f 82"};
out << hex << buffer; // i think the problem is
here
out.close();
cout << "test.bin created" << endl;
return 0;
}
The expected screen output of od -t x1 test.bin is:
ELF /usr/l
i really has no idea about it.......please help