Ignoring whitespace?

I'm doing exercises from Accelerated C++, and one exercise consists of making a triangle. I don't want you to tell me how to make the entire triangle, but please help me here.
By incrementing "s", I want to add more and more whitespace between the asterisks for each line.
The output I get looks like this:
**
**
**
**
**
**
**

The code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int s = 0;
	const string space1(s, ' ');
	
	for (s = 0; s != 7; ++s)
	{
		cout << "*" + space1 + "*" << endl;
	}

	cout << "\n\nPress ENTER to continue...";
	cin.get();

	return 0;
}


Thanks!
Last edited on
Well, maybe you should construct the string inside the loop.
You're now creating a string consisting of zero spaces, so that output is to be expected...
Last edited on
Thanks mate :p
Topic archived. No new replies allowed.