C ++ 2D向量和操作 [英] C++ 2D vector and operations
本文介绍了C ++ 2D向量和操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C ++中创建 2D向量
并找到 length
和
?
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?
谢谢。
推荐答案
如果您的目标是进行矩阵计算,请使用 Boost :: uBLAS 。这个库有很多线性代数函数,并且可能比手工创建的任何东西快很多。
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.
如果你是一个受虐狂者,想要坚持使用 std :: vector
,您需要执行以下操作:
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
这篇关于C ++ 2D向量和操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文