如何用c++读取.asc文件的数据,急!
张若曦❤️pb?
2024-11-17 05:31:49
最佳回答
这个程序应该可以读(假定数据文件中没有第一行):#include<iostream>#include<fstream>using namespace std;struct line{char date[9],time[6];double open,high,low,close;int value,tick_count;};void main(){line *m;m=new line[437730];if(!m){cout <<"error!\n";return;}ifstream fin("f1.txt",ios::in);char t;int i=0; fin.getline(m[i].date,9,',');while(!fin.fail()){fin.getline(m[i].time,6,',');fin >>m[i].open >>t >>m[i].high >>t >>m[i].low >>t >>m[i].close;fin >>t >>m[i].value >>t >>m[i].tick_count;fin.ignore(1);t=',';cout <<m[i].date <<t <<m[i].time <<t <<m[i].open <<t<<m[i].high <<t <<m[i].low <<t <<m[i].close<<t <<m[i].value <<t <<m[i].tick_count <<endl;i++;fin.getline(m[i].date,9,',');}fin.close();delete[]m;return ;} 20210311