Border for 2D array

Hi, I have a function below that outputs a matrix (2d array) the output looks like this:

1 2 3
4 5 6
7 8 9

But I want to to look like this:

|1 2 3|
|4 5 6|
|7 8 9|



what do I need to add to my for loops?

1
2
3
4
5
6
7
8
9
10
11
12

for ( int i = 0, j = 0; i < CONSTANT_SIZE; i++){

		cout << endl;
					
		for (int j = 0; j < CONSTANT_SIZE; j++){				
			
			cout << matrix[i][j];
			cout << setw(5);		
		}
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
for ( int i = 0; i < CONSTANT_SIZE; i++ )
{

	cout << '|';
					
	for ( int j = 0; j < CONSTANT_SIZE;  j++ )
	{				
		cout << matrix[i][j];
		cout << setw(5);		
	}
	cout << setw(1) << '|';		
	cout << endl;
}
thanks
Topic archived. No new replies allowed.