使用c++从.txt中读取第三个坐标
read from .txt the third coordinate using c++
我有一个.txt文件,里面有点的真实坐标。场景是摄像机面对墙壁;在他们中间我有一个盒子。我想在.txt中只获取引用框的点,所以我想从坐标中读取第三个分量,意思是深度值,以及它是否大于某个距离来支撑所有的线。
file.txt
0.005545 0.065641.6354
0.235443 0.354642.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;
}
使用std::ifstream
读取文件。
std::string line;
std::ifstream input_file;
input_file.open("input_file.txt");
// Read the file one line at a time
while (std::getline(input_file, line))
{
// Do your thing
}
input_file.close();
提示:写一个新文件,稍后重命名。
相关文章:
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 在 2D 向量中使用第三个 [ ] 有什么意义?
- 如何通过按下第三个窗口中的按钮,将QString从一个窗口获取到另一个窗口
- 如何知道n!是否可以表示为三个连续数字的乘法?
- 我有三个 getline,但是一旦编译,输入就太多了
- 我遇到了黑客排名中的问题"TWO STRINGS"的三个测试用例的分段错误。原因是什么?
- 有没有更好的方法对C++中的三个整数进行排序?
- 如何检查第三个 API 是否在 Linux 中为 c/c++ 程序创建了一个新线程?
- 为什么 getch 在按下函数或箭头键时返回三个值?
- 使用三个数字比较器进行排序
- 我想在C++代码中比较这三个术语
- 我的动态链接队列在同一输出流中调用时不正确地输出三个返回函数
- 我该如何编码,使计算机知道两个名称条目和三个名称条目之间的区别
- 为什么我需要三个嵌套的大括号来调用赋值运算符,将const引用到二维数组
- 如何通过通用引用或std::forward将这三个c++模板函数合并为一个
- 首先处理第二个和第三个堆与第一个和第二个堆之间的逻辑差异
- 最小二乘多项式拟合仅适用于偶数个坐标
- 异常处理:如果用户输入不是三个特定字符之一
- 为什么将三个变量与 == 一起比较会计算为 false?
- 使用c++从.txt中读取第三个坐标