C++读取txt点云数据代码
时间: 2023-03-30 19:02:00 浏览: 180
C++代码实现读取txt文件代码
4星 · 用户满意度95%
你好,以下是读取txt点云数据的代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#define MAX_POINTS 10000
typedef struct {
float x, y, z;
} Point;
int main() {
FILE *fp;
char filename[] = "point_cloud.txt";
Point points[MAX_POINTS];
int num_points = ;
fp = fopen(filename, "r");
if (fp == NULL) {
printf("Error opening file %s\n", filename);
exit(1);
}
while (fscanf(fp, "%f %f %f", &points[num_points].x, &points[num_points].y, &points[num_points].z) == 3) {
num_points++;
if (num_points >= MAX_POINTS) {
printf("Maximum number of points exceeded\n");
break;
}
}
fclose(fp);
printf("Read %d points from file %s\n", num_points, filename);
return ;
}
```
希望能对你有所帮助。
阅读全文