How do I append 10 arrays to form a single array in c++? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow do you set, clear, and toggle a single bit?What are the differences between a pointer variable and a reference variable in C++?How do I iterate over the words of a string?The Definitive C++ Book Guide and ListWhat is the “-->” operator in C++?How do I use arrays in C++?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why are elementwise additions much faster in separate loops than in a combined loop?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionWhy is it faster to process a sorted array than an unsorted array?

How are presidential pardons supposed to be used?

Make it rain characters

How do you keep chess fun when your opponent constantly beats you?

Windows 10: How to Lock (not sleep) laptop on lid close?

Segmentation fault output is suppressed when piping stdin into a function. Why?

Can a 1st-level character have an ability score above 18?

Match Roman Numerals

Does Parliament hold absolute power in the UK?

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

How to test the equality of two Pearson correlation coefficients computed from the same sample?

Python - Fishing Simulator

Why is superheterodyning better than direct conversion?

Difference between "generating set" and free product?

What was the last x86 CPU that did not have the x87 floating-point unit built in?

Semisimplicity of the category of coherent sheaves?

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

Mortgage adviser recommends a longer term than necessary combined with overpayments

What aspect of planet Earth must be changed to prevent the industrial revolution?

Is this wall load bearing? Blueprints and photos attached

How to copy the contents of all files with a certain name into a new file?

Are my PIs rude or am I just being too sensitive?

Did the new image of black hole confirm the general theory of relativity?

How many people can fit inside Mordenkainen's Magnificent Mansion?

Searching for a differential characteristic (differential cryptanalysis)



How do I append 10 arrays to form a single array in c++?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow do you set, clear, and toggle a single bit?What are the differences between a pointer variable and a reference variable in C++?How do I iterate over the words of a string?The Definitive C++ Book Guide and ListWhat is the “-->” operator in C++?How do I use arrays in C++?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why are elementwise additions much faster in separate loops than in a combined loop?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionWhy is it faster to process a sorted array than an unsorted array?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-2















Let's say I have these 10 previously declared arrays in my code.



 int arr1[] = 1,2,3,4,5,6,7,8,9,10;
int arr2[] = 1,2,3,4,5,6,7,8,9,10;
int arr3[] = 1,2,3,4,5,6,7,8,9,10;
int arr4[] = 1,2,3,4,5,6,7,8,9,10;
int arr5[] = 1,2,3,4,5,6,7,8,9,10;
int arr6[] = 1,2,3,4,5,6,7,8,9,10;
int arr7[] = 1,2,3,4,5,6,7,8,9,10;
int arr8[] = 1,2,3,4,5,6,7,8,9,10;
int arr9[] = 1,2,3,4,5,6,7,8,9,10;
int arr10[] = 1,2,3,4,5,6,7,8,9,10;


Basically, I want to append all 10 of these arrays one after another to make one single array.



 ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[] 


How would I go about doing this? This question might seem trivial for some, but I'm new to C++ and can not figure out how to do it. Please help and thanks in advance.










share|improve this question
























  • What do you mean by add all 10 of these arrays to one single array? like [A]+[B]+...+[J] = [Z] or [Z] = [[A][B]...[J]]

    – RC0993
    Mar 22 at 5:00











  • Like this: ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[]

    – bdbasinger
    Mar 22 at 5:02












  • So, you want to create a matrix?

    – Havenard
    Mar 22 at 5:05











  • Is there a constraint of using arrays? Are the sizes of all arrays pre defined/ preknown? if not then you may use linked list. otherwise if the things are pre defined then its simple to declare a resultant array n populate it

    – RC0993
    Mar 22 at 5:07











  • Yes the sizes are predefined. How would I declare a resultant array and populate it?

    – bdbasinger
    Mar 22 at 5:09

















-2















Let's say I have these 10 previously declared arrays in my code.



 int arr1[] = 1,2,3,4,5,6,7,8,9,10;
int arr2[] = 1,2,3,4,5,6,7,8,9,10;
int arr3[] = 1,2,3,4,5,6,7,8,9,10;
int arr4[] = 1,2,3,4,5,6,7,8,9,10;
int arr5[] = 1,2,3,4,5,6,7,8,9,10;
int arr6[] = 1,2,3,4,5,6,7,8,9,10;
int arr7[] = 1,2,3,4,5,6,7,8,9,10;
int arr8[] = 1,2,3,4,5,6,7,8,9,10;
int arr9[] = 1,2,3,4,5,6,7,8,9,10;
int arr10[] = 1,2,3,4,5,6,7,8,9,10;


Basically, I want to append all 10 of these arrays one after another to make one single array.



 ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[] 


How would I go about doing this? This question might seem trivial for some, but I'm new to C++ and can not figure out how to do it. Please help and thanks in advance.










share|improve this question
























  • What do you mean by add all 10 of these arrays to one single array? like [A]+[B]+...+[J] = [Z] or [Z] = [[A][B]...[J]]

    – RC0993
    Mar 22 at 5:00











  • Like this: ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[]

    – bdbasinger
    Mar 22 at 5:02












  • So, you want to create a matrix?

    – Havenard
    Mar 22 at 5:05











  • Is there a constraint of using arrays? Are the sizes of all arrays pre defined/ preknown? if not then you may use linked list. otherwise if the things are pre defined then its simple to declare a resultant array n populate it

    – RC0993
    Mar 22 at 5:07











  • Yes the sizes are predefined. How would I declare a resultant array and populate it?

    – bdbasinger
    Mar 22 at 5:09













-2












-2








-2


0






Let's say I have these 10 previously declared arrays in my code.



 int arr1[] = 1,2,3,4,5,6,7,8,9,10;
int arr2[] = 1,2,3,4,5,6,7,8,9,10;
int arr3[] = 1,2,3,4,5,6,7,8,9,10;
int arr4[] = 1,2,3,4,5,6,7,8,9,10;
int arr5[] = 1,2,3,4,5,6,7,8,9,10;
int arr6[] = 1,2,3,4,5,6,7,8,9,10;
int arr7[] = 1,2,3,4,5,6,7,8,9,10;
int arr8[] = 1,2,3,4,5,6,7,8,9,10;
int arr9[] = 1,2,3,4,5,6,7,8,9,10;
int arr10[] = 1,2,3,4,5,6,7,8,9,10;


Basically, I want to append all 10 of these arrays one after another to make one single array.



 ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[] 


How would I go about doing this? This question might seem trivial for some, but I'm new to C++ and can not figure out how to do it. Please help and thanks in advance.










share|improve this question
















Let's say I have these 10 previously declared arrays in my code.



 int arr1[] = 1,2,3,4,5,6,7,8,9,10;
int arr2[] = 1,2,3,4,5,6,7,8,9,10;
int arr3[] = 1,2,3,4,5,6,7,8,9,10;
int arr4[] = 1,2,3,4,5,6,7,8,9,10;
int arr5[] = 1,2,3,4,5,6,7,8,9,10;
int arr6[] = 1,2,3,4,5,6,7,8,9,10;
int arr7[] = 1,2,3,4,5,6,7,8,9,10;
int arr8[] = 1,2,3,4,5,6,7,8,9,10;
int arr9[] = 1,2,3,4,5,6,7,8,9,10;
int arr10[] = 1,2,3,4,5,6,7,8,9,10;


Basically, I want to append all 10 of these arrays one after another to make one single array.



 ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[] 


How would I go about doing this? This question might seem trivial for some, but I'm new to C++ and can not figure out how to do it. Please help and thanks in advance.







c++ c++11






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 5:04









RC0993

291217




291217










asked Mar 22 at 4:58









bdbasingerbdbasinger

858




858












  • What do you mean by add all 10 of these arrays to one single array? like [A]+[B]+...+[J] = [Z] or [Z] = [[A][B]...[J]]

    – RC0993
    Mar 22 at 5:00











  • Like this: ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[]

    – bdbasinger
    Mar 22 at 5:02












  • So, you want to create a matrix?

    – Havenard
    Mar 22 at 5:05











  • Is there a constraint of using arrays? Are the sizes of all arrays pre defined/ preknown? if not then you may use linked list. otherwise if the things are pre defined then its simple to declare a resultant array n populate it

    – RC0993
    Mar 22 at 5:07











  • Yes the sizes are predefined. How would I declare a resultant array and populate it?

    – bdbasinger
    Mar 22 at 5:09

















  • What do you mean by add all 10 of these arrays to one single array? like [A]+[B]+...+[J] = [Z] or [Z] = [[A][B]...[J]]

    – RC0993
    Mar 22 at 5:00











  • Like this: ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[]

    – bdbasinger
    Mar 22 at 5:02












  • So, you want to create a matrix?

    – Havenard
    Mar 22 at 5:05











  • Is there a constraint of using arrays? Are the sizes of all arrays pre defined/ preknown? if not then you may use linked list. otherwise if the things are pre defined then its simple to declare a resultant array n populate it

    – RC0993
    Mar 22 at 5:07











  • Yes the sizes are predefined. How would I declare a resultant array and populate it?

    – bdbasinger
    Mar 22 at 5:09
















What do you mean by add all 10 of these arrays to one single array? like [A]+[B]+...+[J] = [Z] or [Z] = [[A][B]...[J]]

– RC0993
Mar 22 at 5:00





What do you mean by add all 10 of these arrays to one single array? like [A]+[B]+...+[J] = [Z] or [Z] = [[A][B]...[J]]

– RC0993
Mar 22 at 5:00













Like this: ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[]

– bdbasinger
Mar 22 at 5:02






Like this: ArrayOfArrays = arr1[], arr2[], arr3[], arr4[], arr5[], arr6[], arr7[], arr8[], arr9[], arr10[]

– bdbasinger
Mar 22 at 5:02














So, you want to create a matrix?

– Havenard
Mar 22 at 5:05





So, you want to create a matrix?

– Havenard
Mar 22 at 5:05













Is there a constraint of using arrays? Are the sizes of all arrays pre defined/ preknown? if not then you may use linked list. otherwise if the things are pre defined then its simple to declare a resultant array n populate it

– RC0993
Mar 22 at 5:07





Is there a constraint of using arrays? Are the sizes of all arrays pre defined/ preknown? if not then you may use linked list. otherwise if the things are pre defined then its simple to declare a resultant array n populate it

– RC0993
Mar 22 at 5:07













Yes the sizes are predefined. How would I declare a resultant array and populate it?

– bdbasinger
Mar 22 at 5:09





Yes the sizes are predefined. How would I declare a resultant array and populate it?

– bdbasinger
Mar 22 at 5:09












4 Answers
4






active

oldest

votes


















2















Basically, I want to append all 10 of these arrays one after another to make one single array.




You cannot do that.



The closest you can get to that is by using std::array.



std::array<int, 10> arr1 = 1,2,3,4,5,6,7,8,9,10;
...
std::array<int, 10> arr10 = 1,2,3,4,5,6,7,8,9,10;

std::array<std::array<int, 10>, 10> arrayOfArray = arr1, ..., arr10;





share|improve this answer






























    1















    I want to append all 10 of these arrays one after another to make one
    single array ?




    You can have array of pointers like



    int *ArrayOfPointers[10] = &arr1, &arr2, &arr3, &arr4, &arr5, &arr6, &arr7, &arr8, &arr9, &arr10;


    Here ArrayOfPointers is array of 10 int pointers i.e it can store address of 10 one dimension int array like arr1, arr2 etc.



    I assume there may be better method than what I'm suggesting in advance C++ for the same task.






    share|improve this answer
































      1














      Try this approach:



      #include <iostream>
      #include <vector>

      int arr1[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
      int arr2[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
      // ...other arrays here...

      // We pass a reference to a vector and return the same vector for performance reasons.
      // Compiler often can optimize that into a better code.
      std::vector<int> append(std::vector<int> & vec, int * data, int size)

      for (int i = 0; i < size; ++i)
      vec.push_back(data[i]);
      return vec;


      int main()

      std::vector<int> data;

      data = append(data, arr1, 10);
      data = append(data, arr2, 10);

      for (auto i : data)
      std::cout << i << ", ";
      std::cout << std::endl;
      return 0;



      Also, in C++ there are good containers for storing arrays, try searching for std::array and std::vector containers. First is a fixed size static array, the other one is dynamic.






      share|improve this answer






























        0














        In C++ it is unnecessary and ill-advised to use C-style arrays. For arrays of
        constant size you may use std::array
        and for arrays of variable size, std::vector



        It looks rather as if what you actually want is a constant two-dimensional matrix
        and to be able to access each of its rows as as a constant array, but do not
        know how to initialise a two-dimensional matrix. If that's the case, here's how:



        #include <iostream>
        #include <array>

        std::array<std::array<int,10>,10> matrix =
        1,2,3,4,5,6,7,8,9,10,
        1,2,3,4,5,6,7,8,9,10,
        1,2,3,4,5,6,7,8,9,10,
        1,2,3,4,5,6,7,8,9,10,
        1,2,3,4,5,6,7,8,9,10,
        1,2,3,4,5,6,7,8,9,10,
        1,2,3,4,5,6,7,8,9,10,
        1,2,3,4,5,6,7,8,9,10,
        1,2,3,4,5,6,7,8,9,10,
        1,2,3,4,5,6,7,8,9,10
        ;

        int main()

        std::array<int,10> const & arr0 = matrix[0];
        for (int const & i : arr0)
        std::cout << i << ' ';

        std::cout << std::endl;

        // Or more simply...
        auto const & arr5 = matrix[5];
        for (auto const & i : arr5)
        std::cout << i << ' ';

        std::cout << std::endl;



        Compile, link and run:



        $ g++ -Wall -Wextra main.cpp && ./a.out
        1 2 3 4 5 6 7 8 9 10
        1 2 3 4 5 6 7 8 9 10


        live demo






        share|improve this answer

























          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293155%2fhow-do-i-append-10-arrays-to-form-a-single-array-in-c%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2















          Basically, I want to append all 10 of these arrays one after another to make one single array.




          You cannot do that.



          The closest you can get to that is by using std::array.



          std::array<int, 10> arr1 = 1,2,3,4,5,6,7,8,9,10;
          ...
          std::array<int, 10> arr10 = 1,2,3,4,5,6,7,8,9,10;

          std::array<std::array<int, 10>, 10> arrayOfArray = arr1, ..., arr10;





          share|improve this answer



























            2















            Basically, I want to append all 10 of these arrays one after another to make one single array.




            You cannot do that.



            The closest you can get to that is by using std::array.



            std::array<int, 10> arr1 = 1,2,3,4,5,6,7,8,9,10;
            ...
            std::array<int, 10> arr10 = 1,2,3,4,5,6,7,8,9,10;

            std::array<std::array<int, 10>, 10> arrayOfArray = arr1, ..., arr10;





            share|improve this answer

























              2












              2








              2








              Basically, I want to append all 10 of these arrays one after another to make one single array.




              You cannot do that.



              The closest you can get to that is by using std::array.



              std::array<int, 10> arr1 = 1,2,3,4,5,6,7,8,9,10;
              ...
              std::array<int, 10> arr10 = 1,2,3,4,5,6,7,8,9,10;

              std::array<std::array<int, 10>, 10> arrayOfArray = arr1, ..., arr10;





              share|improve this answer














              Basically, I want to append all 10 of these arrays one after another to make one single array.




              You cannot do that.



              The closest you can get to that is by using std::array.



              std::array<int, 10> arr1 = 1,2,3,4,5,6,7,8,9,10;
              ...
              std::array<int, 10> arr10 = 1,2,3,4,5,6,7,8,9,10;

              std::array<std::array<int, 10>, 10> arrayOfArray = arr1, ..., arr10;






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 22 at 5:14









              R SahuR Sahu

              171k1298196




              171k1298196























                  1















                  I want to append all 10 of these arrays one after another to make one
                  single array ?




                  You can have array of pointers like



                  int *ArrayOfPointers[10] = &arr1, &arr2, &arr3, &arr4, &arr5, &arr6, &arr7, &arr8, &arr9, &arr10;


                  Here ArrayOfPointers is array of 10 int pointers i.e it can store address of 10 one dimension int array like arr1, arr2 etc.



                  I assume there may be better method than what I'm suggesting in advance C++ for the same task.






                  share|improve this answer





























                    1















                    I want to append all 10 of these arrays one after another to make one
                    single array ?




                    You can have array of pointers like



                    int *ArrayOfPointers[10] = &arr1, &arr2, &arr3, &arr4, &arr5, &arr6, &arr7, &arr8, &arr9, &arr10;


                    Here ArrayOfPointers is array of 10 int pointers i.e it can store address of 10 one dimension int array like arr1, arr2 etc.



                    I assume there may be better method than what I'm suggesting in advance C++ for the same task.






                    share|improve this answer



























                      1












                      1








                      1








                      I want to append all 10 of these arrays one after another to make one
                      single array ?




                      You can have array of pointers like



                      int *ArrayOfPointers[10] = &arr1, &arr2, &arr3, &arr4, &arr5, &arr6, &arr7, &arr8, &arr9, &arr10;


                      Here ArrayOfPointers is array of 10 int pointers i.e it can store address of 10 one dimension int array like arr1, arr2 etc.



                      I assume there may be better method than what I'm suggesting in advance C++ for the same task.






                      share|improve this answer
















                      I want to append all 10 of these arrays one after another to make one
                      single array ?




                      You can have array of pointers like



                      int *ArrayOfPointers[10] = &arr1, &arr2, &arr3, &arr4, &arr5, &arr6, &arr7, &arr8, &arr9, &arr10;


                      Here ArrayOfPointers is array of 10 int pointers i.e it can store address of 10 one dimension int array like arr1, arr2 etc.



                      I assume there may be better method than what I'm suggesting in advance C++ for the same task.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 22 at 5:15

























                      answered Mar 22 at 5:11









                      AchalAchal

                      9,6632931




                      9,6632931





















                          1














                          Try this approach:



                          #include <iostream>
                          #include <vector>

                          int arr1[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
                          int arr2[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
                          // ...other arrays here...

                          // We pass a reference to a vector and return the same vector for performance reasons.
                          // Compiler often can optimize that into a better code.
                          std::vector<int> append(std::vector<int> & vec, int * data, int size)

                          for (int i = 0; i < size; ++i)
                          vec.push_back(data[i]);
                          return vec;


                          int main()

                          std::vector<int> data;

                          data = append(data, arr1, 10);
                          data = append(data, arr2, 10);

                          for (auto i : data)
                          std::cout << i << ", ";
                          std::cout << std::endl;
                          return 0;



                          Also, in C++ there are good containers for storing arrays, try searching for std::array and std::vector containers. First is a fixed size static array, the other one is dynamic.






                          share|improve this answer



























                            1














                            Try this approach:



                            #include <iostream>
                            #include <vector>

                            int arr1[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
                            int arr2[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
                            // ...other arrays here...

                            // We pass a reference to a vector and return the same vector for performance reasons.
                            // Compiler often can optimize that into a better code.
                            std::vector<int> append(std::vector<int> & vec, int * data, int size)

                            for (int i = 0; i < size; ++i)
                            vec.push_back(data[i]);
                            return vec;


                            int main()

                            std::vector<int> data;

                            data = append(data, arr1, 10);
                            data = append(data, arr2, 10);

                            for (auto i : data)
                            std::cout << i << ", ";
                            std::cout << std::endl;
                            return 0;



                            Also, in C++ there are good containers for storing arrays, try searching for std::array and std::vector containers. First is a fixed size static array, the other one is dynamic.






                            share|improve this answer

























                              1












                              1








                              1







                              Try this approach:



                              #include <iostream>
                              #include <vector>

                              int arr1[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
                              int arr2[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
                              // ...other arrays here...

                              // We pass a reference to a vector and return the same vector for performance reasons.
                              // Compiler often can optimize that into a better code.
                              std::vector<int> append(std::vector<int> & vec, int * data, int size)

                              for (int i = 0; i < size; ++i)
                              vec.push_back(data[i]);
                              return vec;


                              int main()

                              std::vector<int> data;

                              data = append(data, arr1, 10);
                              data = append(data, arr2, 10);

                              for (auto i : data)
                              std::cout << i << ", ";
                              std::cout << std::endl;
                              return 0;



                              Also, in C++ there are good containers for storing arrays, try searching for std::array and std::vector containers. First is a fixed size static array, the other one is dynamic.






                              share|improve this answer













                              Try this approach:



                              #include <iostream>
                              #include <vector>

                              int arr1[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
                              int arr2[] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;
                              // ...other arrays here...

                              // We pass a reference to a vector and return the same vector for performance reasons.
                              // Compiler often can optimize that into a better code.
                              std::vector<int> append(std::vector<int> & vec, int * data, int size)

                              for (int i = 0; i < size; ++i)
                              vec.push_back(data[i]);
                              return vec;


                              int main()

                              std::vector<int> data;

                              data = append(data, arr1, 10);
                              data = append(data, arr2, 10);

                              for (auto i : data)
                              std::cout << i << ", ";
                              std::cout << std::endl;
                              return 0;



                              Also, in C++ there are good containers for storing arrays, try searching for std::array and std::vector containers. First is a fixed size static array, the other one is dynamic.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 22 at 6:37









                              DiodacusDiodacus

                              2276




                              2276





















                                  0














                                  In C++ it is unnecessary and ill-advised to use C-style arrays. For arrays of
                                  constant size you may use std::array
                                  and for arrays of variable size, std::vector



                                  It looks rather as if what you actually want is a constant two-dimensional matrix
                                  and to be able to access each of its rows as as a constant array, but do not
                                  know how to initialise a two-dimensional matrix. If that's the case, here's how:



                                  #include <iostream>
                                  #include <array>

                                  std::array<std::array<int,10>,10> matrix =
                                  1,2,3,4,5,6,7,8,9,10,
                                  1,2,3,4,5,6,7,8,9,10,
                                  1,2,3,4,5,6,7,8,9,10,
                                  1,2,3,4,5,6,7,8,9,10,
                                  1,2,3,4,5,6,7,8,9,10,
                                  1,2,3,4,5,6,7,8,9,10,
                                  1,2,3,4,5,6,7,8,9,10,
                                  1,2,3,4,5,6,7,8,9,10,
                                  1,2,3,4,5,6,7,8,9,10,
                                  1,2,3,4,5,6,7,8,9,10
                                  ;

                                  int main()

                                  std::array<int,10> const & arr0 = matrix[0];
                                  for (int const & i : arr0)
                                  std::cout << i << ' ';

                                  std::cout << std::endl;

                                  // Or more simply...
                                  auto const & arr5 = matrix[5];
                                  for (auto const & i : arr5)
                                  std::cout << i << ' ';

                                  std::cout << std::endl;



                                  Compile, link and run:



                                  $ g++ -Wall -Wextra main.cpp && ./a.out
                                  1 2 3 4 5 6 7 8 9 10
                                  1 2 3 4 5 6 7 8 9 10


                                  live demo






                                  share|improve this answer





























                                    0














                                    In C++ it is unnecessary and ill-advised to use C-style arrays. For arrays of
                                    constant size you may use std::array
                                    and for arrays of variable size, std::vector



                                    It looks rather as if what you actually want is a constant two-dimensional matrix
                                    and to be able to access each of its rows as as a constant array, but do not
                                    know how to initialise a two-dimensional matrix. If that's the case, here's how:



                                    #include <iostream>
                                    #include <array>

                                    std::array<std::array<int,10>,10> matrix =
                                    1,2,3,4,5,6,7,8,9,10,
                                    1,2,3,4,5,6,7,8,9,10,
                                    1,2,3,4,5,6,7,8,9,10,
                                    1,2,3,4,5,6,7,8,9,10,
                                    1,2,3,4,5,6,7,8,9,10,
                                    1,2,3,4,5,6,7,8,9,10,
                                    1,2,3,4,5,6,7,8,9,10,
                                    1,2,3,4,5,6,7,8,9,10,
                                    1,2,3,4,5,6,7,8,9,10,
                                    1,2,3,4,5,6,7,8,9,10
                                    ;

                                    int main()

                                    std::array<int,10> const & arr0 = matrix[0];
                                    for (int const & i : arr0)
                                    std::cout << i << ' ';

                                    std::cout << std::endl;

                                    // Or more simply...
                                    auto const & arr5 = matrix[5];
                                    for (auto const & i : arr5)
                                    std::cout << i << ' ';

                                    std::cout << std::endl;



                                    Compile, link and run:



                                    $ g++ -Wall -Wextra main.cpp && ./a.out
                                    1 2 3 4 5 6 7 8 9 10
                                    1 2 3 4 5 6 7 8 9 10


                                    live demo






                                    share|improve this answer



























                                      0












                                      0








                                      0







                                      In C++ it is unnecessary and ill-advised to use C-style arrays. For arrays of
                                      constant size you may use std::array
                                      and for arrays of variable size, std::vector



                                      It looks rather as if what you actually want is a constant two-dimensional matrix
                                      and to be able to access each of its rows as as a constant array, but do not
                                      know how to initialise a two-dimensional matrix. If that's the case, here's how:



                                      #include <iostream>
                                      #include <array>

                                      std::array<std::array<int,10>,10> matrix =
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10
                                      ;

                                      int main()

                                      std::array<int,10> const & arr0 = matrix[0];
                                      for (int const & i : arr0)
                                      std::cout << i << ' ';

                                      std::cout << std::endl;

                                      // Or more simply...
                                      auto const & arr5 = matrix[5];
                                      for (auto const & i : arr5)
                                      std::cout << i << ' ';

                                      std::cout << std::endl;



                                      Compile, link and run:



                                      $ g++ -Wall -Wextra main.cpp && ./a.out
                                      1 2 3 4 5 6 7 8 9 10
                                      1 2 3 4 5 6 7 8 9 10


                                      live demo






                                      share|improve this answer















                                      In C++ it is unnecessary and ill-advised to use C-style arrays. For arrays of
                                      constant size you may use std::array
                                      and for arrays of variable size, std::vector



                                      It looks rather as if what you actually want is a constant two-dimensional matrix
                                      and to be able to access each of its rows as as a constant array, but do not
                                      know how to initialise a two-dimensional matrix. If that's the case, here's how:



                                      #include <iostream>
                                      #include <array>

                                      std::array<std::array<int,10>,10> matrix =
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10,
                                      1,2,3,4,5,6,7,8,9,10
                                      ;

                                      int main()

                                      std::array<int,10> const & arr0 = matrix[0];
                                      for (int const & i : arr0)
                                      std::cout << i << ' ';

                                      std::cout << std::endl;

                                      // Or more simply...
                                      auto const & arr5 = matrix[5];
                                      for (auto const & i : arr5)
                                      std::cout << i << ' ';

                                      std::cout << std::endl;



                                      Compile, link and run:



                                      $ g++ -Wall -Wextra main.cpp && ./a.out
                                      1 2 3 4 5 6 7 8 9 10
                                      1 2 3 4 5 6 7 8 9 10


                                      live demo







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Mar 22 at 14:43

























                                      answered Mar 22 at 12:51









                                      Mike KinghanMike Kinghan

                                      32.9k870119




                                      32.9k870119



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293155%2fhow-do-i-append-10-arrays-to-form-a-single-array-in-c%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현