创建以变量m为个数的点云指针的c++代码
下面是一个示例代码,它创建了一个以变量m为个数的点云指针:
#include <iostream>
struct Point {
float x;
float y;
float z;
};
int main() {
int m;
std::cout << "Enter the number of points: ";
std::cin >> m;
// 创建点云指针
Point* pointCloud = new Point[m];
// 输入点的坐标
for (int i = 0; i < m; i++) {
std::cout << "Enter the coordinates of point " << i+1 << ": ";
std::cin >> pointCloud[i].x >> pointCloud[i].y >> pointCloud[i].z;
}
// 输出点的坐标
std::cout << "Point cloud coordinates:\n";
for (int i = 0; i < m; i++) {
std::cout << "Point " << i+1 << ": ";
std::cout << "(" << pointCloud[i].x << ", " << pointCloud[i].y << ", " << pointCloud[i].z << ")\n";
}
// 释放点云指针内存
delete[] pointCloud;
return 0;
}
这段代码首先会要求用户输入点的个数m,然后动态分配了一个大小为m的Point数组作为点云指针。接下来,它会要求用户依次输入每个点的坐标,并将其存储在对应的Point结构体中。最后,它会输出点云中每个点的坐标,并在程序结束前释放点云指针的内存
原文地址: https://www.cveoy.top/t/topic/hU16 著作权归作者所有。请勿转载和采集!