1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| namespace tools
{
Eigen::MatrixXi createMatrix( std::wstring path )
{
// Create flow
std::ifstream file(toANSI(path).c_str(), std::ios::in);
// Current line
std::string line;
unsigned int row, column = 0;
// Matrix
Eigen::MatrixXi matrix;
// typedef for a better readable code
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
// The separator
boost::char_separator<char> separator( " " );
// If open file success
if (file)
{
while (std::getline(file, line))
{
// Personal tokeniser
tokenizer tokens( line, separator );
for (tokenizer::iterator tokenIterator = tokens.begin(); tokenIterator != tokens.end(); ++tokenIterator)
{
std::string tempString = *tokenIterator;
std::wcout << atoi( tempString.c_str() ) << std::endl;
matrix(column, row) = atoi( tempString.c_str() );
++column;
}
++row;
}
file.close();
}
else
{
std::wcerr << "Error! Can not open file: " << path << std::endl;
exit(EXIT_FAILURE);
}
return matrix;
}
} |
Partager