在C ++中为boost :: numeric :: ublas :: vector分配多个值 [英] assign multiple values to boost::numeric::ublas::vector in c++
问题描述
我想知道如何一次将多个值分配给向量:
I want to know how I can assign multiple values to a vector at once:
#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace boost::numeric::ublas;
int main()
{
vector<double> v1(3);
v1(0)=0;
v1(1)=0.1;
v1(2)=0.05;
v1(3)=0.25;
return 0;
}
我想一次分配所有值. 像这样:
I want to assign all the values at once. something like:
v1 << 0,0.1,0.05,0.25;
我尝试了运算符+ =,但有一个错误,但我认为运算符+ =适用于std :: vector而不是boost :: .... vector
I tried operator += and there is an error, but I think operator += works for std::vector not boost::....vector
推荐答案
看看文档示例基本上,您需要v1 <<= 0, 1, 2;
,请参阅文档中的更多示例.不幸的是,该库尚不支持initializer_list: http ://boost.2283326.n4.nabble.com/Initializing-from-an-initializer-list-td4647029.html
Basically, you need v1 <<= 0, 1, 2;
, see more examples in the docs. Unfortunately this library doesn't support initializer_list's yet: http://boost.2283326.n4.nabble.com/Initializing-from-an-initializer-list-td4647029.html
这篇关于在C ++中为boost :: numeric :: ublas :: vector分配多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!