#include <fstream>
#include <vector>
#include <Eigen/Dense>
#include <iostream>
int main()
{
std::vector<Eigen::Vector3d> world_points;
{
std::string file("/home/qiang/pointPairs/3D_01_1.txt");
std::ifstream infile(file);
while(true) // 最常见的错误读取方式为: while(!infile.eof()) {...;}
{
double x, y, z;
infile >> x >> y >> z;
if(infile.eof())
{
break;
}
Eigen::Vector3d vec(x, y, z);
world_points.push_back(vec);
}
infile.close();
}
std::cout << "valid lines: " << world_points.size() << "\n";
for (auto &p : world_points)
{
std::cout << p.transpose() << "\n";
}
return 0;
}
使用ifstream避免重复读取txt文件最后一行的正确读取方法
最新推荐文章于 2023-06-14 22:32:24 发布