分享

从文华财经Mytrader2009中读取数据 ? COS论坛 | 统计之都

 weicat 2013-11-14

接abel的帖子,,,现日数据的破解如下:

#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;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多