由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - New C++ programmer, need to ask a I/O file read question
相关主题
c的问题请问strcpy()和memcpy()的写法问题  (转载)
请教一道c/c++题如何让这个cur变量正确指向新地址
帮忙看看这几段程序有问题吗?请教一道题 (转载)
C++ string to int Problem一个极简单的程序求教
C pass string 问题关于文件读取的C++ 问题?
问个关于cin的问题C++ read matrix from txt file
weird outputC++ string类输入数据的问题
请帮忙看看这个字符函数的错误在哪里问个简单的memory allocation 的问题。
相关话题的讨论汇总
话题: file话题: c++话题: new话题: null话题: strtok
进入Programming版参与讨论
1 (共1页)
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,"|");

1 (共1页)
进入Programming版参与讨论
相关主题
问个简单的memory allocation 的问题。C pass string 问题
问个C/C++题目问个关于cin的问题
strcat()weird output
请教一个C++关于输入输出的问题请帮忙看看这个字符函数的错误在哪里
c的问题请问strcpy()和memcpy()的写法问题  (转载)
请教一道c/c++题如何让这个cur变量正确指向新地址
帮忙看看这几段程序有问题吗?请教一道题 (转载)
C++ string to int Problem一个极简单的程序求教
相关话题的讨论汇总
话题: file话题: c++话题: new话题: null话题: strtok