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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:24:33+00:00 2026-05-25T00:24:33+00:00

I have a 4d vector and I am trying to add values to it.

  • 0

I have a 4d vector and I am trying to add values to it. I don’t receive any compiler errors, but when running it, the program freezes when it gets to the line where I am adding values to this vector.

I initialize the vector in a header file like this:

std::vector<std::vector<std::vector<std::vector<unsigned int> > > > _celllist;

The array is then sized with the following:

_celllist.resize(_vnx);
 for(int i=0;i<_vnx;i++) 
    {
        //y axis size
        _celllist[i].resize(_vny);
            for(int j=0;j<_vny;j++)
            {
                //z axis size
                _celllist[i][j].resize(_vnz);
            }
    }

This line then causes the program to crash:

_celllist[ix][iy][iz].push_back(i);

Note that ix, iy, and iz are all int and i is an unsigned int.

Can anyone see what might be going wrong here? 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-25T00:24:33+00:00Added an answer on May 25, 2026 at 12:24 am

    The operator[] does not expand or guarantee that the element is valid. It’s a faster version of at() with little or no error checking:

    Convert your code to the safer version for now:

    _celllist.at(ix).at(iy).at(iz).push_back(i);
    

    This new code will throw an out_of_range exception if your indices are off.

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

Sidebar

Related Questions

I'm new with vectors. I'm trying to add objects to a vector. But the
I have been trying to grasp the basics of Support Vector Machines, and downloaded
I have a vector containing the values 0, 1, 2 and 3. What I
I'm trying to add some songs to a vector inside a class. One of
I am trying to add the ScannerKit API to my application i have added
I am trying to add a set of new ModelImages to a vector, and
!Hi I have a hard time trying to copy vector of pointers to Point.
So, I'm trying to load resources, add them to a dictionary, and have a
I am trying to create a program that will create a vector, generate 100
I have a vector of type template class and I am trying to print

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.