padding strings

I'm displaying a string on the screen that I want to appear as though it's highlighted. I figured out how to highlight the text of the string, but the problem is that each string that could potentially print on the screen is of different sizes. So the amount of highlighting changes which each string.

I want to make each string 20 chars long no matter what. Even if there's only 10 letters, I want 10 more significan spaces behind the string so the whole 20 char section highlights.

Is there a simple way to add padded spaces to one end of a string or the other?
while (str.length()<20)str+=' ';
or
if (str.length()<20)str+=string(20-str.length(),' ');
Thank you.
Those will be very slow, however.
Try calculating the number of spaces, and then adding them, rather than using a loop.
Topic archived. No new replies allowed.