Whoa!!! Actually i didn't think about the constructing a string.
The result you're getting is normal. Setting y=0 means you're creating a first string with only spaces and the second one is empty.
The string constructor builds up a string with n specified characters. In your case the first string si a 5-y length string of ' ', second one is a 0+y length string of 64+y characters.
To remove the white space you can create the strings this way:
Note that I left the 4 since it's the number of characters you want to print, so if you wanto to parameterize the function... (and notice that the 3 in the first string constructor is 4-1 )Code:#include<iostream> #include<string> using namespace std; int main() { for(int y = 0; y < 4; y++) { cout << string((3-y),' '); cout << string((1+y), 65+y); cout << "\n"; } cin.get(); return 0; }
Regards,
Tesctassa