l*******o 发帖数: 44 | 1 I was using matlab doing some scientific calculation. Used to use matlab
read my data file. The data file format is:
123|456|date|c|45.36
234|567|date|c|67.80
something like that. The whole file is huge, which means it have more than
10000 lines of those data.
Recently I am transfering to use C++. a true new rookie learner.
I was trying to use something the book teach, it seems if I use getline(),
it will automatically save the file in a string. and I don't really know how
to transfer from this | k****f 发帖数: 3794 | 2 FILE*fp=fopen("youdata","r");
char buf[1000];
int first,second;
char third[10],fourth[10];
double fifth;
while(fgets(buf,sizeof(buf),fp)){
char*p=strtok(buf,"|");
if(p==NULL)break;
first=atoi(p);
p=strtok(NULL,"|");
second=atoi(p);
p=strtok(NULL,"|");
strcpy(third,p);
p=strtok(NULL,"|");
strcpy(fourth,p);
p=strtok(NULL,"|");
fifth=atof(p);
}
fclose(fp);
how
.
me
【在 l*******o 的大作中提到】 : I was using matlab doing some scientific calculation. Used to use matlab : read my data file. The data file format is: : 123|456|date|c|45.36 : 234|567|date|c|67.80 : something like that. The whole file is huge, which means it have more than : 10000 lines of those data. : Recently I am transfering to use C++. a true new rookie learner. : I was trying to use something the book teach, it seems if I use getline(), : it will automatically save the file in a string. and I don't really know how : to transfer from this
| l*******o 发帖数: 44 | 3 many many many many many THANKS
Let me try it. thanks a lot.
【在 k****f 的大作中提到】 : FILE*fp=fopen("youdata","r"); : char buf[1000]; : int first,second; : char third[10],fourth[10]; : double fifth; : while(fgets(buf,sizeof(buf),fp)){ : char*p=strtok(buf,"|"); : if(p==NULL)break; : first=atoi(p); : p=strtok(NULL,"|");
|
|