std::istream operator>> should be added

Submitted by Helmut Jarausch

Assigned to Nobody

Link to original bugzilla bug (#622)

Description

There should be an input operator>> which can read files written with the
built-in output operator<<

The following addition to Eigen/src/Core/IO.h would be quite helpful

+template<typename Derived>
+std::istream & operator >>
+(std::istream & s,

  • MatrixBase<Derived> & m)
    +{
  • for (int i = 0; i < m.rows(); ++i)
  • for (int j = 0; j < m.cols(); j++)
  •  s >> m(i,j);  
  • return s;
    +}

} // end namespace Eigen

IMHO there is no need for a fancy input operator (using non-white-space separators, e.g.) since the standard output operator doesn't create such files.

In teaching C++ using Eigen, it's so much easier to tell the students that
a matrix/vector written with operator<< can be read in by this new operator>>

Thanks for considering this tiny addition,

Helmut Jarausch
Lehrst. f. Numerische Mathematik
RWTH-Aachen, Germany

Blocking

#209 #814 (closed)

Edited by Eigen Bugzilla