📄 matio.htm
字号:
<html>
<head>
<link rel=stylesheet href="styles.css" type="text/css">
<title>Matrix I/O operators</title>
</head>
<body>
<h6 align=right>
<a href="matfunc.htm">Prev</a> |
<a href="manual.htm">Up</a> |
Next
</h6>
<h2>Matrix I/O operators</h2>
<p>
The following I/O operators are available for the matrix class.
</p>
<pre><code><a href="#e1">1</a>. istream& operator>> (istream& is, valarray<T>& v);
<a href="#e2">2</a>. istream& operator>> (istream& is, matrix<T>& m);
<a href="#e3">3</a>. ostream& operator<< (ostream& os, const valarray<T>& v);
<a href="#e4">4</a>. ostream& operator<< (ostream& os, const matrix<T>& m);
</code></pre>
<p>
<ol>
<li><a name="e1"></a>Use operator <i>>></i> to read a <i>valarray</i>
vector or row/column of a matrix object from a input stream like <i>cin</i> or a file.
</li><br><br>
<li><a name="e2"></a>Use operator <i>>></i> to read a matrix object
from a input stream like <i>cin</i> or a file.
</li><br><br>
<li><a name="e3"></a>Use operator <i><<</i> to write a <i>valarray</i>
vector or row/column of a matrix object to a output stream like <i>cout</i>
or a file.
</li><br><br>
<li><a name="e4"></a>Use operator <i><<</i> to write a matrix object to
a output stream like <i>cout</i> or a file.
</li><br><br>
</ol>
</p>
<h5>Examples</h5>
<pre><code>typedef matrix<double> Matrix;
typedef valarray<double> Vector;
Matrix A(4,4);
Vector V(4);
size_t i=1,j=2;
cin >> A[i][j]; // Read A<sub><small>ij</small></sub> th element from standard input
cin >> A.diag()[1]; // Read the 2nd diagonal element of matrix A
cin >> A[i]; // Read the <i>i</i> th row of matrix A
cin >> A(j); // Read the <i>j</i> th column of matrix A
cin >> A.diag(); // Read the diagonal elements of matrix A
cin >> V; // Read the vector V
cout << A(i,j); // Write A<sub><small>ij</small></sub> th element to standard output
cout << A.diag()[1]; // Write the 2nd diagonal element of matrix A
cout << A[i]; // Write the <i>i</i> th row of matrix A
cout << A(j); // Write the <i>j</i> th column of matrix A
cout << A.diag(); // Write the diagonal elements of matrix A
cout << V; // Write the vector V
</code></pre>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -