Explain this program please

I've been learning programming on my spare time and I found a program that makes a diamond, i know how to make shapes with for loops, but I really can't figure out how this one works, any explanation/help would be greatly appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

using namespace std;

int main()
{
	for (int i = 0; i < 9; ++i)

		cout << "\t" << string(abs(4 - i), ' ') << string(9 - 2 * abs(4 - i), '*') << endl;
	cout << endl;
	

	return 0;
}
http://www.cplusplus.com/reference/string/string/string/

See the 6th constructor (the 'fill' constructor).
"Fills the string with n consecutive copies of character c."

And it's calculating n using whatever the value of i is in that current iteration and the abs method:

http://www.cplusplus.com/reference/cstdlib/abs/
Topic archived. No new replies allowed.