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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:46:05+00:00 2026-05-17T15:46:05+00:00

vector<vector<int> > mymatrix; vector<int> *ptr_vec; How do I make the ptr_vec point to the

  • 0
vector<vector<int> > mymatrix;
vector<int> *ptr_vec;

How do I make the ptr_vec point to the vectors which are inside mymatrix one after another. In more details Let’s say mymatrix.at(0).size() gives 10, and mymatrix.at(1).size() gives 14 ..if I go ptr_vec->at(15) it should give me the fifth member in mymatrix.at(1) hope it doesn’t confuse anybody.

ok now that I showed the point , think of mymatrix as separated vectors like this
vector<int> row1, row2, row3; which might be simpler still how to make that ptr have all the addresses of what ever other vectors??

  • 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-17T15:46:05+00:00Added an answer on May 17, 2026 at 3:46 pm

    Given your clarification “how to make that ptr have all the addresses of what ever other vectors” I think you placed the * incorrectly in your declaration.

    It think you meant ptr_vec to be a vector of pointers.

    If so, …

    #include <iostream>
    #include <vector>
    #include <stddef.h>
    using namespace std;
    
    typedef ptrdiff_t Size;
    
    template< class Elem >
    Size countOf( vector< Elem > const& v ) { return v.size(); }
    
    int main()
    {
        vector< vector<int> >   mymatrix( 10, vector<int>( 14 ) );
        vector<int*>            ptr_vec;
    
        for( Size i = 0;  i < countOf( mymatrix );  ++i )
        {
            vector<int>&    v   = mymatrix[i];
    
            for( Size j = 0;  j < countOf( v );  ++j )
            {
                ptr_vec.push_back( &v[j] );
            }
        }
    
        // Init data
        for( Size i = 0;  i < countOf( mymatrix );  ++i )
        {
            vector<int>&    v   = mymatrix[i];
    
            for( Size j = 0;  j < countOf( v );  ++j )
            {
                v[j] = 100*i + j + 1;
            }
        }
    
        // Display
        for( Size i = 0;  i < countOf( ptr_vec );  ++i )
        {
            cout << *ptr_vec[i] << ' ';
        }
        cout << endl;
    }
    

    Cheers & hth.,

    – Alf

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

Sidebar

Related Questions

header file: private: vector<int*>* nums; public slots: void buttonClicked(); cpp file: NewWindow(){ int one
Lets say I have a vector of int which I've prefilled with 100 elements
Are there any known hash algorithms which input a vector of int's and output
I have a vector of int vector<int> p; now I want to delete one
I read a integer binary file to int vector. When I use the Sort
Suppose we'd like to remove duplicate values from a vector of int s. The
I have a function that creates a 2D vector void generate(int n) { vector<
vector<int> l; for(int i=0;i<10;i++){ l.push_back(i); } I want the vector to only be able
vector<int>& mergesort(vector<int> &a) { if (a.size() == 1) return a; int middle = a.size()
Example code : int main() { std::vector<int> v1{1, 2, 3, 4, 5, 6, 7,

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.