64,662
社区成员
发帖
与我相关
我的任务
分享
//测试例子:51 03 00 00 41 42 43 58 05 00 00 00 31 32 33 34 35
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
int main(int argc, char *argv[])
{
ifstream ifile(argv[1],ios_base::binary);
vector<string> v;
char c;
while(ifile.get(c)) {
string s;
unsigned i,d;
switch (c) {
case '\x51':
s+= '\x51';
i=3;
break;
case '\x58':
s+= '\x58';
i=4;
break;
//加入你另外的处理,4字节不够可设另外的类型.
}
d=0;
for(unsigned int t=0; t<i; t++) {
ifile.get(c);
d = d | (c << t*8);
s+=c;
}
char *up=new char[d];
ifile.read(up, d);
s.append(up,d);
v.push_back(s);
delete []up;
}
//输出之.
for(vector<string>::iterator j=v.begin(); j!=v.end(); ++j) {
for(string::iterator si=(*j).begin(); si!=(*j).end(); ++si) {
cout.width(2);
cout.fill('0');
cout << unsigned (*si) << ' ';
}
cout << endl;
}return 0;
}