C++ 2D vector and operations

Simplicity picture Simplicity · Jan 30, 2011 · Viewed 13.1k times · Source

How can one create a 2D vector in C++ and find its length and coordinates?

In this case, how are the vector elements filled with values?

Thanks.

Answer

chrisaycock picture chrisaycock · Jan 30, 2011

If your goal is to do matrix computations, use Boost::uBLAS. This library has many linear algebra functions and will probably be a lot faster than anything you build by hand.

If you are a masochist and want to stick with std::vector, you'll need to do something like the following:

std::vector<std::vector<double> > matrix;
matrix.resize(10);
matrix[0].resize(20);
// etc