read from .txt the third coordinate using c++ -
i have .txt file real coordinates of points. scenario camera facing wall; between them have box. want in .txt points refering box, want read third component coordinates, meaning depth value , if it's bigger distance supprime line.
file.txt
0.005545 0.06564 1.6354
0.235443 0.35464 2.6575
if(value>2.5) { delete line .txt }
all coordinates separated white space , lines intro.
thanks
i think work:
#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 = 2; < dataarray.size(); += 3) { if(dataarray[i] < thresh) { (int j = i-2; j <= i; ++j) newfile << dataarray[j] << " "; newfile << endl; } } myfile.close(); return 0; }
Comments
Post a Comment