在我的程序工作,我有整数的向量的向量。现在,我想从向量的向量采取一个载体,有它在另一个载体容器操作,但我得到的错误...迭代器载体媒介的失败,一个1-d矢量
|error: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >' to non-scalar type 'std::vector<int, std::allocator<int> >' requested|
的什么,我试图做的是如下的例子.. ..
#include <vector>
using namespace std;
vector<vector<int> > k (13,5);
void some_funct() {
vector<int> new_v (k[2].begin(), k[2].end()); //This line is what throws the error
//here I do some stuff with new_v (e.g. sort it)
}
我不知道我在做什么错。我尝试了一些东西,比如将begin()和end()迭代器分配给const迭代器类型...... vector<int>::const_iterator it = k[2].begin();
但是这也不起作用。
这应该工作(因为K [X]将是一个向量),但我不知道什么错误。任何帮助表示赞赏!
编辑:
我的代码修改后,我注意到,有实际上是一个错误。我做了vector<int> new_v = (k[2].begin(),k[2].end());
而不是做vector<int> new_v (k[2].begin(),k[2].end());
。
我要感谢Rob因为我主动将我的代码复制并粘贴到SO中,我注意到了我的错误。
谢谢你的帮助!
你确定错误不在上面的行吗?应该是,'std :: vector> k(13,std :: vector (5));'? –
不,我的程序是相当复杂的,有吨 –
在任何情况下示出的两条线之间的代码,'的std ::矢量 new_v(K [2]);'应该工作一样好。 –