How to use output formatting (%3d) in C++

1 Answer

0 votes
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	int arr[] = { 1, 2, 3, 2, 5, 6, 6, 2 };
	int size = sizeof(arr) / sizeof(int);

	for (int i = 0; i < size; i++)
		cout << arr[i] << setw(3);

	return 0;
}

/*
run: 

1  2  3  2  5  6  6  2

*/

 



answered Feb 11, 2016 by avibootz

Related questions

...