#include <fstream> #include <strtk.hpp> // http://www.partow.net/programming/strtk std::string filename("Resources/bones.out"); // assuming the file is text std::fstream fs; fs.open(filename.c_str(), std::ios::in); if(fs.fail()) return false; const char *whitespace = " \t\r\n\f"; std::string line; std::vector<float> floats; std::vector<std::string> strings; float x = 0.0, y = 0.0, z = 0.0; std::string xs, ys, zs; // process each line in turn while( std::getline(fs, line ) ) { // Removing beginning and ending whitespace // can prevent parsing problems from different line endings. // formerly accomplished with boost::algorithm::trim(line) strtk::remove_leading_trailing(whitespace, line); // strtk::parse combines multiple delimiters in these cases if( strtk::parse(line, whitespace, floats ) ) { std::cout << "succeed" << std::endl; // floats contains all the values on the in as floats } if( strtk::parse(line, whitespace, strings) ) { std::cout << "succeed" << std::endl; // strings contains all the values on the in line as strings } if( strtk::parse(line, whitespace, x, y, z) ) { std::cout << "succeed" << std::endl; // x,y,z contain the float values. parse fails if more than 3 floats are on the line } if( strtk::parse(line, whitespace, xs, ys, zs) ) { std::cout << "succeed" << std::endl; // xs,ys,zs contain the strings. parse fails if more than 3 strings are on the line } }
Here is how I will resolve it. You can choose the method of data analysis.
DannyK Feb 28 '14 at 18:33 2014-02-28 18:33
source share