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 6231639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:58:14+00:00 2026-05-24T09:58:14+00:00

Okay, so I need to create a 3D data-structure at run-time, I decided to

  • 0

Okay, so I need to create a 3D data-structure at run-time, I decided to use std::vector, the problem is as follows: I know the dimension of the 1st dimension at instantiation time (when I create the object I’m using it in), but I don’t know the dimension of the second until run-time, and the size of 3rd dimensions can vary. I have created the 3D vector and the run-time doesn’t complain, however I’m having difficulty assigning values to the elements.

This code is part of an object I’m creating. In the class definition I have:

std::vector< std::vector< std::vector<double> > > splits;

Then in the object constructor, in order to create/allocate the first dimension, I have:

for(int i=0; i<sizeOfDimOne; i++){ //create 1st dimension
    splits.push_back( std::vector< std::vector<double> >() );
}

based on user input I need to create 2nd dimension of a certain size, I call a method for this:

for(int i=0; i<sizeOfDimOne; i++){
    for(int j=0; j<sizeOfDimTwo; j++) //create second dimension
        splits[i].push_back( std::vector<double>() );
}

However, when I get to assigning values:

for(int i=0; i<sizeOfDimThree; i++){
   splits[dim1][dim2].push_back( someValue ); //adding an element to the 3rd dim
}

(The someValue changes constantly (and is a double), and you don’t have to worry about lower dimension indexing, everything checks out.) The problem is – when I checked splits[dim1][dim2][i] the value was 0.0 for (presumably all) entries, naturally this is not what was provided by someValue.

I have also tried creating the 3rd dimension using .resize(sizeOfDimThree) and then assigning using

splits[dim1][dim2][i] = whatever;

but that didn’t work at all – no object/element was created at all.

I realize this perhaps isn’t the most straight forward manner of phrasing the question, but I believe it is the most accurate, as there might be multiple-points of failure.

  • 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-24T09:58:15+00:00Added an answer on May 24, 2026 at 9:58 am

    Okay, so it turns out, that technically everything was correct (albeit inefficient, which I got around by using .resize() for appropriate dimensions in turn), my ‘problem’ was (as it tends to be) a very stupid mistake, to verify that everything was assigned I used:

    printf("value assigned: %d", splits[dim1][dim2][dim3]);
    

    instead of (since splits is a double):

    printf("value assigned: %.3f", splits[dim1][dim2][dim3]);
    

    Moral of the story: pay attention to how you treat the variable datatype & post full source code.

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

Sidebar

Related Questions

Okay, I need some help here. This is the same old "can't use an
Okay, I'm a newbie in C# but I need to create a simple GUI,
Okay, I need help. I'm usually pretty good at SQL queries but this one
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my
Okay, here's the setup: I work in HPC, and we're preparing for the need
Okay. I know this looks like the typical Why didn't he just Google it
Okay, pretty simple question. I think I need to drop in some escape characters,
I need to create a statement in LINQ with 3 tables and OR condition.
Okay, I need some solid OOP advice. Here's the setup: I have a player
Okay, after pounding my head against the wall for about 2 hours, I need

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.