Cannot align output values to the right, setw() right

Hey guys I cannot get my array value to align to the right.
I do not know what I am doing wrong, I just can never seem to get the numbers to align, even with other projects.
And yes I am using <iomanip>.
I tried placing the "right" in front of setw(), removing "right" and leaving setw() by itself,I set setw() as setw(5) and it just makes the program look even more weird.
I know the code is not wrong its just that small glitch.

I want the output of the array to look like this:
1 45 765 6
32 45 12 389
100 1 9 50
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 void displayArray(int numArray[][COLS])
{
	cout << "Here is the data in the 2-Dimensional array: \n";

	for (int i = 0; i < ROWS; i++)
	{
		for (int j = 0; j < COLS; j++)
		{

			cout << setw(2) << right << "\t" << numArray[i][j];
		}
		cout << endl;
	}
	
}
Last edited on
http://www.cplusplus.com/reference/ios/right/
edit
Sorry i posted the wrong page
http://www.cplusplus.com/reference/iomanip/setw/

Your doing it right, but setw(2) is not large enough, try setw(5) or 10.
Last edited on
It did not work, it only created a bigger gap in between.
1
2
3
4
5
6
7
Enter integers into the 2-D Dimensional array:

Here is the data in the 2-Dimensional array:
                21              21              215             6541
                125             13              312             526
                514             153             154             1456
Press any key to continue . . .
You do set the width for the tabulator.
Remove the tab or print it before the setw.
Topic archived. No new replies allowed.