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

  • Home
  • SEARCH
  • 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 9268733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:56:03+00:00 2026-06-18T14:56:03+00:00

In C++ I understand that in order to create a dynamic array you need

  • 0

In C++ I understand that in order to create a dynamic array you need to use vectors. However I have a problem when I need to find information I put in the vector.

For example:
Lets say I have a simple vector that stores the name of a person and a small message the wrote. In the vector how do I find where Bill is located.

I was also trying to understand how to do this in PHP when I posted this question.

  • 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-06-18T14:56:05+00:00Added an answer on June 18, 2026 at 2:56 pm

    Indeed you seam confused. Let me try to help you.

    One thing that is maybe confusing you: std::vector is not a geometric vector. It’s only a sequence of data of the same type that is contiguous in memory. So it’s like an array.

    a) Determine the size of a vector based on a variable. For example if
    I was using an array it would look something like array [x][y] ( I
    know it’s not possible to do this). How would I do this with a vector

    std::vector is basically a automatically managed dynamic array.

    It means that it IS an array inside, but it’s managed by code that will make sure that array grows (gets bigger) when you try to add more data than it current capacity can hold.

    Actually, std::vector is a class template. It means that it’s not a real class, it’s code that the compiler will use to generate itself a real class. If I say

    std::vector<int> my_ints; // this is a vector of ints
    

    This vector can only hold ints. And then:

    std::vector<std::string> name_list;
    

    this one hold std::string objects.

    As I was saying, inside, it’s only code to manage an array dynamically. You can think the previous examples as if it was like that:

    class
    {
        unsigned long size; // count of elements contained in this container
        unsigned long capacity; // count of elements that the memory allocated by the array can hold
        int* array; // array containing the values, created using new, destroyed using delete
    } 
    my_ints;
    

    This is an oversimplified view of how it is inside, so don’t assume it’s exactly like that, but it might be useful.

    Now, when you add values, the value is copied in the memory of the array, in an element that is not used yet (through push_back() for example) or writing over an element already existing (using insert() for example).

    If you add a value and the capacity of the vector is not enough to hold all values, then the the vector will automatically grow: it will create a much bigger array, copy it’s current values inside, copy the additional value too, then delete the array it had before.
    It’s important to understand this: if a vector grows, then you can’t assume that it’s data is always at the same adress in memory, so pointers to it’s data can’t be trusted.

    b) second how would I using the push back command to store the value
    of a variable inside a specific spot. Again if I was using an array
    it’d be like array[x][y] += q. Where x and y are the spot in the array
    and q is the value.

    You don’t use push_back() to add a value between two values, you use insert().

    The syntaxe array[x][y] += q Will certainly not do what you describe. It will add q to the value at the position array[x][y].

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

Sidebar

Related Questions

I need to create a view that displays Order Header information and I need
I understand that in order to swipe between activities I need to use the
I have come to an idea that in order to create a prefix method
I know that in order to create an object of ArrayList type I need
So I understand that in order to create a universal app and make it
I understand that Haskell's filter is a high order function (meaning a function that
Some projects are so big that in order to understand for example a function
I understood that in order to use cookies inside of phonegap native app there
I understand that this question may be subjective, this is why I need an
I have a sample application that I have created to understand an experiment with

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.