无法在c++ Builder中写入.csv文件到StringGrid

Cannot write .csv file to StringGrid in C++ Builder

本文关键字:csv 文件 StringGrid c++ Builder      更新时间:2023-10-16

编辑:代码块编辑,现在唯一的问题是只有最后一行。csv文件是打印在StringGrid的每一行。原因是什么呢?提前谢谢。

基本上,项目的一个模块确实创建了一个输出文件,其中包含以逗号分隔格式的点坐标,如下所示:

#pt,     x     ,     y     ,z    
124,4500003.833,3499999.500,0
125,4500003.833,3499999.833,0
126,4500003.833,3500000.167,0

我要做的是用另一个模块读取.csv并将其放入StringGrid。

 FILE *coord;
 //some other things here
while (fgets(line,100,DosyaGiris)!=NULL) {
 sscanf(line,"%d,%lf,%lf,%lf",&number,&x,&y,&z);
        for (col = 0; col < 4; col++) {
                StringGrid1->Cells[0][row] = IntToStr(number);
                StringGrid1->Cells[1][row] = FloatToStr(x);
                StringGrid1->Cells[2][row] = FloatToStr(y);
                StringGrid1->Cells[3][row] = FloatToStr(z);
        }
}

请建设性一点,祝你过得愉快。

由于不必要的for循环,它不能工作,现在它工作了

        int i= 0;
        while (fgets(line,100,DosyaGiris)!=NULL){
            sscanf(line,"%d,%lf,%lf,%lf",&ID,&x,&y,&z);
                StringGrid1->Cells[0][i+1] = IntToStr(ID);
                StringGrid1->Cells[1][i+1] = FloatToStr(x);
                StringGrid1->Cells[2][i+1] = FloatToStr(y);
                StringGrid1->Cells[3][i+1] = FloatToStr(z);
                i++;
        }