简体   繁体   English

将向量{x,y,z}插入另一个向量?

[英]Insert vector {x, y, z} into another vector?

I'm looking for some pointers on inserting or pushing a vector into another vector. 我正在寻找关于将向量插入或推入另一个向量的一些指针。

The idea is I have vec1 = {1, 2, 3} for example. 这个想法是例如我有vec1 = {1,2,3}。 Then I want to insert this into vec2 before next vec1 = {4, 5, 6} turns up. 然后,我想在下一个vec1 = {4,5,6}出现之前将其插入vec2。

The problem is I don't want vec 2 to read {1, 2, 3, 4, 5, 6}, I want it to read 问题是我不希望vec 2读取{1、2、3、4、5、6},我希望它读取

vec2 = {1, 2, 3}, {4, 5, 6},... etc vec2 = {1、2、3},{4、5、6}等

Is this possible or I'm I completely mad. 这可能吗,或者我完全生气了。 Any help will be great. 任何帮助都会很棒。

Thanks. 谢谢。

You can use a vector of vector of integers. 您可以使用整数向量的向量。 Like this : 像这样 :

std::vector<std::vector<int>> vecofvecs = { {1,2,3}, {4,5,6} };

You can also use this : 您也可以使用:

#include <vector>
int main()
{
    std::vector<std::vector<int>> vecofvecs;
    std::vector<int> subvec1 = { 1,2,3 };
    std::vector<int> subvec2 = { 4,5,6 };

    vecofvecs.push_back(subvec1);
    vecofvecs.push_back(subvec2);

    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM