Tutorial by Examples

#include <stddef.h> // size_t, ptrdiff_t //----------------------------------- Machinery: using Size = ptrdiff_t; template< class Item, size_t n > constexpr auto n_items( Item (&)[n] ) noexcept -> Size { return n; } //----------------------------------- Us...
// Example of raw dynamic size array. It's generally better to use std::vector. #include <algorithm> // std::sort #include <iostream> using namespace std; auto int_from( istream& in ) -> int { int x; in >> x; return x; } auto main() -> int { ...
// Example of std::vector as an expanding dynamic size array. #include <algorithm> // std::sort #include <iostream> #include <vector> // std::vector using namespace std; int int_from( std::istream& in ) { int x = 0; in >> x; return x; } ...
// A fixed size raw array matrix (that is, a 2D raw array). #include <iostream> #include <iomanip> using namespace std; auto main() -> int { int const n_rows = 3; int const n_cols = 7; int const m[n_rows][n_cols] = // A raw array matrix. ...
Unfortunately as of C++14 there's no dynamic size matrix class in the C++ standard library. Matrix classes that support dynamic size are however available from a number of 3rd party libraries, including the Boost Matrix library (a sub-library within the Boost library). If you don't want a dependenc...
An array is just a block of sequential memory locations for a specific type of variable. Arrays are allocated the same way as normal variables, but with square brackets appended to its name [] that contain the number of elements that fit into the array memory. The following example of an array uses...

Page 1 of 1