Using the C++ Math Library | ![]() ![]() |
Overview
A C++ stream is a sequence of data objects. Often a stream consists of a sequence of characters. C++ streams encompass all the I/O devices attached to a computer (keyboard, screen, disk, etc.).
There are two basic types of streams: input streams and output streams. Streams can be attached to one of many types of data sources, or sinks, such as files, strings, and the screen, so that input can be read from and written to both disk files and the user's terminal. Refer to your C++ reference for a complete explanation of streams and C++'s input and output facilities.
C++ defines three standard streams, cin
, cout
, and cerr
. cin
is bound to standard input, cout
to standard output, and cerr
to standard error. The MATLAB C++ Math Library provides standard C++-style stream input (>>
) and output (<<
) operators for mwArray
objects. For example, to send an array A
to the standard output, you write:
cout << A << endl;
To read an array in from standard input, you write:
cin >> A;
To send an array A
to standard error, you write:
cerr << A << endl;
![]() | Using Array Stream I/O | Example - Array Stream I/O (ex1.cpp) | ![]() |