gpt4 book ai didi

c++ - 使用 C++ 从 .txt 中读取第三个坐标

转载 作者:行者123 更新时间:2023-11-28 07:30:30 25 4
gpt4 key购买 nike

我有一个包含点的真实坐标的 .txt 文件。场景是相机面对墙壁;在他们之间我有一个盒子。我只想在 .txt 中获取引用框的点,所以我想从坐标中读取第三个组件,这意味着深度值,如果它大于某个距离,则对所有行进行填充。

文件.txt

0.005545 0.06564 1.6354

0.235443 0.35464 2.6575

如果(值>2.5){ 从 .txt 中完全删除行

所有的坐标都用空格和带有介绍的行分隔。

谢谢

最佳答案

我认为这会起作用:

#include <fstream>
#include <vector>
#include <iterator>
#include <algorithm>

#define THRESH 2.5f

using namespace std;
int main()
{
vector<float> DataArray;

ifstream myfile("test.txt");

copy(istream_iterator<float>(myfile),
istream_iterator<float>(),
back_inserter(DataArray));
myfile.close();

ofstream newfile("test.txt");

for(int i = 2; i < DataArray.size(); i += 3)
{
if(DataArray[i] < THRESH)
{
for (int j = i-2; j <= i; ++j)
newfile << DataArray[j] << " ";
newfile << endl;
}
}

myfile.close();
return 0;
}

关于c++ - 使用 C++ 从 .txt 中读取第三个坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17833072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com