实习的第二天接到了一个小任务,其中一个环节是将一堆只有x和z坐标的数据从txt文件中读出保存成点(xyz)的格式,数据是激光扫描所得,数据的y坐标需要后续的计算处理,下面的程序也是写了好半天才写出来,毕竟是刚刚开始工作,以后的效率一定会提上去的。
#include<iostream>
#include<sstream>
#include<string>
#include<fstream>
#include<vector>
#include<pcl/io/io.h>
#include<pcl/point_types.h>
#include<pcl/io/pcd_io.h>
#include<pcl/visualization/cloud_viewer.h>
using namespace std;
//创建坐标点 x y z
typedef struct Point
{
double x;
double y;
double z;
};
//按照字符串之间的空格进行字符切割
void split(const string& s, vector<string>& elems, char delim = ' ')
{
stringstream ss;
ss.str(s); //str返回临时指针
string ele;
while (getline(ss, ele, delim))
{
elems.push_back(ele);//将切割后的单字符元素传入集合elems中
}
}
int main()
{
int row = 218;//修改 列
ifstream Read;
Read.open("C:\\Users\\asus\\Desktop\\程序\\demo1.txt");
string String; //创建一个字符串 储存每行的字符串
Point p;
vector<Point> VecP;
while (getline(Read, String)) //从文件中读的