常用的一个功能,读取txt中的数据,保存在自己定义的数组中:
struct myPoint
{
myPoint() {};
myPoint(const double &x,const double &y,const double& z) {
this->x = x; this->y = y; this->z = z;
}
public:
double x, y, z;
};
void loadDataFromTxt(const std::string &fileName) {
std::ifstream loadFile(fileName,ios::in);
if (!loadFile) {
return;
}
std::vector<myPoint> points;
std::string str;
while (getline(loadFile, str))
{
std::stringstream ss(str);
myPoint p;
while (ss>>p.x>>p.y>>p.z)
{
points.emplace_back(p);
}
}
}