我有一个 std::vector,我想把它转换成 arma::rowvec
我已经搞定了:
vector<int> x = foo();
rowvec a;
vector<int>::const_iterator iter2;
int j = 0;
for(iter2 = x.begin(); iter2 != x.end(); ++iter2) {
a(j++,0) = *iter2;
}
a.print("a");
但我得到:
error: Mat::operator(): out of bounds
terminate called after throwing an instance of 'std::logic_error'
what():
如果不是a(j++,0) = *iter2;
我a << *iter2;
在最终的 rowvec 中使用,我只会得到最后一个元素。