Can't display Dynamic 2D array

Hello, I'm unable to print my 2D array. When entering the for loop in display(), my program seems to run continuously, without an error message. Everything compiles fine and I can't seem to find what is causing this issue. Below is the header file along with the display and load functions.

Graph.h:
class Graph{

public:
Graph(); // constructor
~Graph(); // destructor

// Load the graph from a file
void load(char *filename);

// Display the adjacency matrix
void display() const;

// Display the depth first search from the given vertex
void displayDFS(int vertex) const;

// Display the breadth first search from the given vertex
void displayBFS(int vertex) const;

// Determine whether the graph is bipartite or not
bool isBipartite() const;

private:
// TODO: Complete the private section of the class.
int **arr;
int vertices;
void DFS(int vertex, bool *marked) const;
};

Graph.cpp:
Graph::Graph(){
}

// Destructor
Graph::~Graph(){
for(int i = 0; i < vertices; i++)
delete arr[i];
delete arr;
}

// Load the graph from a file
void Graph::load(char *filename){
ifstream file;
file.open(filename);
int x, y;

file >> vertices;
cout << "vertices: " << vertices << endl;
int **arr = new int*[vertices];
for(int i = 0; i < vertices; i++){
arr[i] = new int[vertices]();
}

while(file >> x >> y){
arr[x][y] = 1;
arr[y][x] = 1;
cout << "adding vertex" << x << y << endl;
}
//cout << "finish load" << endl;
//cout << arr[0][1] << endl;
//cout << arr[0][0] << endl;
}

// Display the adjacency matrix
void Graph::display() const{
//cout << "starting display" << endl;

for(int i = 0; i < vertices; i++){
for(int j = 0; j < vertices; j++)
cout << arr[i][j] << " ";
cout << endl;
}
//cout << "finish display" << endl;
}

Thank you.
can we assume you load, then print, and nothing in the middle?
Yes I go directly from loading a graph to printing it. I have found that the error is a segmentation fault somewhere, but I can't seem to find it.
This is a cleaner view:

In Graph.h:

private:
// TODO: Complete the private section of the class.
int **arr;
int vertices ;
void DFS(int vertex, bool *marked) const;

In Graph.cpp:

void Graph::load(char *filename){
ifstream file;
file.open(filename);
int x, y;

file >> vertices;
cout << "vertices: " << vertices << endl;
int **arr = new int*[vertices];
for(int i = 0; i < vertices; i++){
arr[i] = new int[vertices];
}

for(int i = 0; i < vertices; i++){
for(int j = 0; j < vertices; j++)
arr[i][j] = 0;
}

while(file >> x >> y){
arr[x][y] = 1;
arr[y][x] = 1;
cout << "adding vertex" << x << y << endl;
}
file.close();
}

// Display the adjacency matrix
void Graph::display() const{

for(int i = 0; i < vertices; i++){
for(int j = 0; j < vertices; j++)
cout << arr[i][j] << " ";
cout << endl;
}
}
Topic archived. No new replies allowed.