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

Are there any known hash algorithms which input a vector of int's and output
Specifically, with a SortedMap<Vector<String>, int> I get dimensions expected after this ( int )
#include <iostream> #include <vector> using namespace std; int main() { vector< vector<int> > dp(50000,
Does anybody know why vector<int> test(10); int a=0; for_each(test.begin(),test.end(),(_1+=var(a),++var(a))); for_each(test.begin(),test.end(),(cout << _1 << ));
If I have a vector of pairs: std::vector<std::pair<int, int> > vec; Is there and
#include <vector> std::vector<long int> as; long int a(size_t n){ if(n==1) return 1; if(n==2) return
char *values = 3 1 4 15; vector<int> array; I want to populate the
I want to eliminate the junk that I'm getting on the vector<int> synsAux below.
In C++ often do something like this: typedef map<int, vector<int> > MyIndexType; Where I
I've got a node struct struct Node{CString text, int id;}; in a sorted vector.

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.