Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey I was wondering how I would align my text on a C++ console application. I belive console applications can only have a width of 800px so I figure there must be some sort of implemented alignment system. Really I want to display some numbers on the same line on the right and some on the left. Thanks
Posted

0) The font used in a console window must be a non-proportional font. This is the default selection, and most end-users don't even knowmthey can change the font, much less how to do it.

1) If you want to right-align numeric values, you have to convert the number to a string, and pad the left side of the string with a sufficient number of spaces. Look at the various options available for the sprintf function. (Left-alignment is accomplished the same way, only you're padding the number on the right.
 
Share this answer
 
v2
Comments
CPallini 15-Nov-10 13:35pm    
Actually printf format specifiers allows directly number alignment (and you can do the same with std::cout).
WurmInfinity 15-Nov-10 16:08pm    
seems to not really be what I want. I honestly dont think I can do what I want it too doooo but thanks anyways :D
#realJSOP 17-Nov-10 7:58am    
@CPallini - thta's why I said look at the sprintf method. It allows you to do all of that with the correct formatting specifiers.
calculate the length of your display area. (DispLen)
calculate the length of your text. (TextLen)
LeftMargin = DispLen - TextLen;

now add white space LeftMargin times before your text then print.

Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900