Using the C++ Math Library | ![]() ![]() |
Operators
In addition to the indexing operators, there are three additional operators in the mwArray
interface. The first two operators, <<
and >>
, are used for stream input and output. Technically, these stream operators are not member functions; they are friend functions:
friend inline ostream& operator<<(ostream &os, const mwArray&)
Calling this operator inserts an mwArray
object into the given stream. If the stream is cout
, the contents of the mwArray
object appear on the terminal screen or elsewhere if standard output has been redirected on the command line. This function simply invokes Write()
as described below.
friend inline istream& operator>>(istream &is, mwArray&)
This is the stream extraction operator, capable of extracting, or reading, an mwArray
from a stream. The stream can be any C++ stream object, for example, standard input, a file, or a string. This function simply invokes Read()
as described below. Using Array Stream I/O in Chapter 8 describes the syntax of the input format.
Note that the >>
and <<
operator functions do not read and write MAT-files.
The stream operators call Read()
and Write()
, mwArray
public member functions.
void Read(istream&)
Reads an mwArray
from an input stream. An array definition consists of an optional scale factor and asterisk, *
, followed by a bracket [
, one or more semicolon-separated rows of double-precision floating-point numbers, and a closing bracket ]
. Using Array Stream I/O in Chapter 8 describes the input format in more detail.
void Write(ostream&, int32 precision =5, int32 line_width =75) const
Formats mwArray
objects using the given precision (number of digits) and line width, and then writes the objects into the given stream. operator<<()
uses the default values shown above, which are appropriate for 80-character-wide terminals.
The third operator is =
, the assignment operator. C++ requires that the assignment operator be a member function. Like the copy constructor (see Constructors), the assignment operator does not actually make a copy of the input array, but rather references (keeps a pointer to) the input array's data; this is an optimization made purely for efficiency, and has no effect on the semantics of assignment. If you write A = B
and then modify B
, the values in A
will remain unchanged:
mwArray &operator=(const mwArray&)
;![]() | Memory Management | Array Size | ![]() |