我可以使用insert函数将元素添加到向量的向量中吗?
|
我想知道,我可以使用insert关键字将元素添加到
vector
的vector
中吗?
例如,对于这个vector
,我有一个vector
vector<int> temp1;
,元素在内部for
循环内添加。在for
循环的结尾,我需要将元素添加到temp1
;
vector<vector<int> >temp1;
for (int a;a<size(),a++){//...
vector<int> temp2;
for (int b=0;b<closer_points;b++){
// some steps here...
vector<int> pt_no=mydata.Find_End_point(my_list,s1,s2);
temp2=pt_no;
}
temp1[a].insert(temp1[a].end(),temp2.begin(),temp2.end());
}
然后,我尝试逐行打印temp1
,因为temp2
的元素出现在一行中。
for(int i=0;i<temp1.size();i++){
for(int j=0;j<temp1[i].size();j++){
cout<<\" t2 \"<<temp1[i][j];
}
cout<<endl;
}
但是,这不起作用。任何人都可以纠正这一点,请...
没有找到相关结果
已邀请:
2 个回复
旗低饶彤
要将范围作为新向量附加到现有的vector_of_vectors中:
如果您还没有14ѭ和
更新资料 如果我这样说;我有一些要点。我想将这些点归为向量,然后将其放在另一个向量中。因此,我猜我的最终输出是向量的向量。例如,最终结果应类似于((1,3),(4,6,9,8,21),(5,7,12),..)。 好的,这里是:
倪蕊悲潍