Prev | Up | Next

Matrix I/O operators

The following I/O operators are available for the matrix class.

1. istream& operator>> (istream& is, valarray<T>& v);
2. istream& operator>> (istream& is, matrix<T>& m);

3. ostream& operator<< (ostream& os, const valarray<T>& v);
4. ostream& operator<< (ostream& os, const matrix<T>& m);

  1. Use operator >> to read a valarray vector or row/column of a matrix object from a input stream like cin or a file.


  2. Use operator >> to read a matrix object from a input stream like cin or a file.


  3. Use operator << to write a valarray vector or row/column of a matrix object to a output stream like cout or a file.


  4. Use operator << to write a matrix object to a output stream like cout or a file.


Examples
typedef techsoft::matrix<double> Matrix;
typedef std::valarray<double> Vector;

using std::cin;
using std::cout;

Matrix A(4,4);
Vector V(4);
size_t i=1,j=2;

cin >> A[i][j];          // Read Aij th element from standard input
cin >> A.diag()[1];      // Read the 2nd diagonal element of matrix A

cin >> A[i];             // Read the i th row of matrix A
cin >> A(j);             // Read the j th column of matrix A
cin >> A.diag();         // Read the diagonal elements of matrix A

cout << A(i,j);          // Write Aij th element to standard output
cout << A.diag()[1];     // Write the 2nd diagonal element of matrix A
cout << A[i];            // Write the i th row of matrix A
cout << A(j);            // Write the j th column of matrix A
cout << A.diag();        // Write the diagonal elements of matrix A