一、相關知識
1、容器vector的使用:需要#include以及using namepace std;
2、結構體的使用:struct;
3、.檔案輸入流:需要#include
二、代碼編寫
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<vector>
#include<string>
using namespace std;
//模型輸入資料結構設定
struct Point_user
{
double x;
double y;
double z;
double Intensity;
double Dist;
};
//建構一個傳回值類型為Point_user類型容器的函數用于點雲資料讀入
vector<Point_user> points_Read(string str);
int main(void)
{
//input data
vector<Point_user> user_Pt;
user_Pt = points_Read("E:/1.txt");
system("pause");
return 0;
}
//建構一個傳回值類型為Point_user類型容器的函數用于點雲資料讀入
vector<Point_user> points_Read(string str_Path)
{
ifstream infile;
infile.open(str_Path);
vector<Point_user> Pts;
if(!infile)
{
cout<<"error"<<endl;
system("pause");
return Pts;;
}
string str;
double t1,t2,t3,t4,t5;
Point_user Pt;
while(infile>>t1>>t2>>t3) //按空格讀取,遇到空白符結束
{
Pt.x = t1;
Pt.y = t2;
Pt.z = t3;
Pts.push_back(Pt);
cout<<Pt.x<<" "<<Pt.y<<" "<<Pt.z<<endl;
}
return Pts;
}
三:資料輸入和輸出
1、資料輸入:
2、結果輸出: