read a matrix from a text file into Eigen matrix

#include <Eigen/Dense>
#include <Eigen/Dense>
#include <vector>
#include <fstream>
#include <igl/list_to_matrix.h>
using namespace std;
void read_matrix(std::string fileName, Eigen::MatrixXd &outputMat) {
fstream cin;;
if (
std::cerr << "Failed to open file: " << fileName << std::endl;
std::cin.get(); }
string s;
vector <vector <double> > matrix;
while (getline(cin, s)) {
stringstream input(s);
double temp;
vector <double> currentLine;
while (input >> temp)
if (!igl::list_to_matrix(matrix, outputMat))
{ std::cerr << "list tom matrix error" << std::endl; std::cin.get();
//return false;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s