Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6380181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:14:05+00:00 2026-05-25T02:14:05+00:00

How do I store a list of arrays into another set of array? I

  • 0

How do I store a list of arrays into another set of array? I tried this way but it doesn’t work.

float data1[5] = {150.0, 203.0, 165.0, 4.0, 36.0};
float data2[5] = {249.0, 255.0, 253.0, 104.0, 2.0};

float allData[2] = {data1, data2};

cout << allData[1][2] << endl;     //this should print 253.0 but it has error

This didn’t allow me to compile. I also tried to change it to float *allData[2] = {data1, data2}; and it allowed me to compile but I don’t get the result I want.

What have I done wrong in this?
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:14:05+00:00Added an answer on May 25, 2026 at 2:14 am

    You should use vectors (this example is in C++11):

    std::vector<float> data1 = {150.0, 203.0, 165.0, 4.0, 36.0};
    std::vector<float> data2 = {249.0, 255.0, 253.0, 104.0, 2.0};
    
    std::vector<std::vector<float>> allData = {data1, data2};
    std::cout << allData[0][0] << std::endl;
    

    Note: possibly you want to store pointers to vectors in allData to prevent copying the data, but you should always take care with such constructs as this could very quickly lead to dangling pointers. This is also the case for the solution with plain arrays by the way.

    Edit, as R. Martinho Fernandes mentioned in comments:

    You can change the construct of allData to:

    std::vector<std::vector<float>> allData = {std::move(data1), std::move(data2)};
    

    It’s worth to note however that after this operation data1 and data2 will be emtpy as their contents are moved to allData. If you do not need them anymore this is the version to prefer (no pointers, no copying).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to store a list of binary codes in a String[] array, such
I want to store a list of numbers (essentially, a set in mathematical terms)
I want to store a list of objects, lets say of type Car, but
I want to have a List or Array of some sort, storing this information
I have an array with a list of objects. I want to split this
I'm trying to use an array to store a list of file names using
How can i display a list of images stored in an array as list
How are lists in python stored internally? Is it an array? A linked list?
I am a beginner in C++. I need to store list of addresses that
How do I store a list of data that is submitted to a controller

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.