Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;使用另一个数组和新值初始化数组 我从Python来C++,如果可能的话,用数组做这个等价: both = [...] a = [a1, a2] + both [a1, a2, ...] b = [b1, b2] + both [b1, b2, ...]_C++_Arrays_Initialization_Concatenation - Fatal编程技术网

C++;使用另一个数组和新值初始化数组 我从Python来C++,如果可能的话,用数组做这个等价: both = [...] a = [a1, a2] + both [a1, a2, ...] b = [b1, b2] + both [b1, b2, ...]

C++;使用另一个数组和新值初始化数组 我从Python来C++,如果可能的话,用数组做这个等价: both = [...] a = [a1, a2] + both [a1, a2, ...] b = [b1, b2] + both [b1, b2, ...],c++,arrays,initialization,concatenation,C++,Arrays,Initialization,Concatenation,您可以使用std::vector std::vector<int> both = {...}; std::vector<int> a = {a1, a2}; a.insert(a.end(), both.begin(), both.end()); std::vector<int> b = {b1, b2}; b.insert(b.end(), both.begin(), both.end()); std::vector两者={…}; 向量a={a1,a2

您可以使用
std::vector

std::vector<int> both = {...};

std::vector<int> a = {a1, a2};
a.insert(a.end(), both.begin(), both.end());

std::vector<int> b = {b1, b2};
b.insert(b.end(), both.begin(), both.end());
std::vector两者={…};
向量a={a1,a2};
a、 插入(a.end(),两个.begin(),两个.end());
向量b={b1,b2};
b、 插入(b.end(),both.begin(),both.end());

用数组做这样的事情,你可以考虑下面的代码

    #include <iostream>
    
    int main()
    {
        int both[] ={1, 2, 3};
        std::cout << sizeof(both)/sizeof(*both);
        int a[sizeof(both)/sizeof(*both) + 2] = {4, 4};
        int b[sizeof(both)/sizeof(*both) + 2] = {5, 5};
        for (int i = 0; i < sizeof(both)/sizeof(*both); ++i)
        {
            a[2+i] = both[i];
            b[2+i] = both[i];
        }
    
        return 0;
    }
#包括
int main()
{
int-both[]={1,2,3};

STD::你需要编写代码来完成这项工作,你现在写了什么?你应该看看STD::VC++:C++中的数组是C中的数组,C中的数组是用来解决时间问题的。那是70年代的时候。你会发现C++中的数组非常简单和愚蠢。喜欢使用.@ Alexander Wilkins。在“请”上,将帮助您解决问题的答案标记为解决方案谢谢!我知道我可以用向量来做这件事,我只是更喜欢用数组,因为我真的不喜欢向量的语法。我知道,愚蠢的推理。