接abel的帖子,,,現(xiàn)日數(shù)據(jù)的破解如下:
#include <iostream>
#include <fstream>
using namespace std;
struct wenhua
{
int date;
float open;
float close;
float high;
float low;
float vol;
float openinterest;
float settleprice;
//float other;
//char c1[6];
};
void error(string errmsg){
cerr<<errmsg<<endl;
cin.get();
exit(1);
}
int main(int argc,char * argv[]){
if(3 != argc )
error("argument must be original dat and output csv");
int c=0;
////////////// try char offset !!! when c==5 success!!!!!/////////////
// while(c<100){
// c++;
ifstream in(argv[1],ios::binary);
if(!in) error("input dat error!");
ofstream out(argv[2],ios::out);
if(!out) error("output csv error!");
wenhua mywh;
int count = 0;
while(!in.eof() ){
in.read((char *)&mywh,sizeof(mywh));
time_t rawtime = mywh.date ;
struct tm * ptm = localtime(&rawtime);
char _date[20];
char _time[20];
memset(&_date,0,sizeof(_date));
memset(&_time,0,sizeof(_time));
sprintf(_date,"%d-%d-%d", ptm->tm_year+1900,ptm->tm_mon + 1,ptm->tm_mday);
sprintf(_time,"%d:%d:%d", ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
cout<<_date<<' '<<_time<<' '<<mywh.date<<' '<<mywh.open<<' '<<mywh.high<<' '
<<mywh.low<<' '<<mywh.close<<' '<<mywh.vol<<' '
<<mywh.openinterest<<' '<<mywh.settleprice<<' '
<<endl;
out<<_date<<','<<mywh.close<<endl;
count++;
// cout<<"offset:"<<c<<endl;
/////////////////set c=5 when successful!!!////////////////
c=5;
char c1[c];
in.read((char *)c1,sizeof(c1));
//cout<<c1<<endl;
}
in.close();
out.close();
// cout<<endl;
// }
return 0;
}
|