0

I m facing problem (in debugging window) to check values of an array of vectors arr once I call a function in which this array is passed as a pointer.

here is my code which has an array of vectors. And i pass this array as pointer to a function named as print_arr which basically prints the values of this array arr

MY CODE :

#include <bits/stdc++.h>
using namespace std;

void print_arr( vector <int> A[] ){
    for ( int i =0; i<3; i++){
        cout<<i<<" -> ";
        for ( int j = 0; j<A[i].size(); j++)
            cout<<A[i][j]<< " " ;
        cout<<endl;
    }
}

// Driver Code
int main()
{
    vector <int> arr[3] ;

    // pushing values int array of vectors
    arr[0].push_back(1) ;
    arr[0].push_back(2) ;
    arr[1].push_back(10) ;
    arr[1].push_back(20) ;
    arr[2].push_back(100) ;
    arr[2].push_back(200) ;

    // printing the array of vector 
    print_arr ( arr ) ;

    return 0 ;

}

I can see values of this array in debug window without any issue, before reaching to the breakpoint which calls this function (line 27) enter image description here

But once my program calls this function, I start facing an issue to view the values of this array under the locals section in the debugging window. enter image description here enter image description here

How am I supposed to view the array elements if i pass the array as a pointer to a function ??

  • Use the command line window to submit a GDB command and type `-exec ` and follow the guidance here -> https://stackoverflow.com/questions/253099/how-do-i-print-the-elements-of-a-c-vector-in-gdb You can also look at `_M_start` under `_M_impl` and feed that address into a memory dump by following this guide - https://stackoverflow.com/questions/59727276/vs-code-memory-view-with-gdb-debugger For any of this to work you need to compile with debug symbols enabled. – Den-Jason Jul 10 '21 at 10:18

0 Answers0