Vectors
The first example shows how to declare and use RWMathVec<T>, the Essential Math Module vector class, to add two vectors.
 
#include <rw/math/mathvec.h> // 1
#include <iostream.h> // 2
int main()
{
RWMathVec<int> iv(10, 0, 1); // 3
RWMathVec<double> dv = "[4 5 8 9 7 5 3 4 3 0]"; // 4
RWMathVec<double> div = RWConvertMathVec<int,double>(iv); // 5
cout << div + dv; // 6
}
//1 This first #include statement declares the class RWMathVec<T>, a vector of elements of type T. You can think of it as describing to the compiler how the class designer (Rogue Wave, in this case) has extended the language to include a new type, RWMathVec<T>.
//2 The second #include statement allows the use of streams for input/output.
//3 The third line defines an RWMathVec<int> with the name iv using a constructor with arguments (vector length, start value, increment). The result is a a vector of 10 integers initialized to [0, 1, 2, ... 9]. See the Class Reference for a complete guide to all of the constructors.
//4 The fourth line defines an RWMathVec<double> with the name dv, also with 10 elements, but initialized using a character string.
//5 The fifth line uses the conversion object RWConvertMathVec to convert the integer vector iv to an RWMathVec<double>.
//6 The sixth line prints the sum of the two vectors. Input and output of vectors using streams is exactly analogous to input and output of basic types like double.