Hello, I would like to know how I can print a pointer to a list, as a list vector. I made a pointer pointing to list and I do not know how to print those values. I tried using an iterator for each position of the vector and printing from start to end of the list, but I could not. It sounds simple, but I can not do it. Does anyone know a way to do this? Here is the code:
#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <list>
#include<iostream>
using namespace std;
int main(int argc, char** argv) {
list<int> *adjV;
list<int>::iterator it;
adjV[0].push_back(10);
adjV[0].push_front(20);
adjV[0].push_back(30);
adjV[1].push_back(45);
adjV[1].push_front(55);
adjV[1].push_back(65);
adjV[2].push_back(80);
adjV[2].push_front(90);
adjV[2].push_back(100);
for (it = adjV[0].begin(); it != adjV[0].end(); it++)
cout << *it << endl;
for (it = adjV[1].begin(); it != adjV[1].end(); it++)
cout << *it << endl;
for (it = adjV[2].begin(); it != adjV[2].end(); it++)
cout << *it << endl;
return 0;
}
A segmentation fault (core dumped) occurs when it executes.