We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
@meaux, that code takes advantage of stream manipulators to format the output buffer: with setw(n) you define the width of the field to display, setfill(' ') lets you choose a padding character, and string(i,'#') builds a string consisting of i times the '#' character.
I had also gone for a one liner inside the loop (not really, as I had to reset a variable on every loop iteration) using std::transform and lambdas on a char array, but this is way more elegant and readable.
Staircase
You are viewing a single comment's thread. Return to all comments →
Good one!! :)
@meaux, that code takes advantage of stream manipulators to format the output buffer: with setw(n) you define the width of the field to display, setfill(' ') lets you choose a padding character, and string(i,'#') builds a string consisting of i times the '#' character.
I had also gone for a one liner inside the loop (not really, as I had to reset a variable on every loop iteration) using std::transform and lambdas on a char array, but this is way more elegant and readable.