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 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

I have a class called Grid that declares a vector of vectors like this:
The Vector API defines 4 different constructors: Vector() Vector(Collection<? extends E> c) Vector(int initialCapacity)
If i have in C++ a pointer to a vector: vector<int>* vecPtr; And i'd
Let's suppose I have a struct like this: struct my_struct { int a; int
I need to find an element position in an std::vector to use it for
I have a std::vector< tr1::shared_ptr<mapObject> > that I'm trying build from data contained in
i have a std::vector, namely vector<vector<vector> > > mdata; i want pass data from
If I put this code in a .cpp file and run it, it runs
I am looking into alternate ways to do a Matrix Multiplication. Instead of storing
I've written a C++ matrix template class. It's parameterized by its dimensions and by

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.