对齐文字 [英] Align Text

查看:76
本文介绍了对齐文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我想知道如何在C ++控制台应用程序上对齐文本.我相信控制台应用程序只能具有800px的宽度,因此我认为必须有某种已实现的对齐系统.真的,我想在右侧的同一行上显示一些数字,在左侧的某些行上显示一些数字.感谢

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

推荐答案

0)控制台窗口中使用的字体必须是非比例字体.这是默认选择,大多数最终用户甚至都不知道可以更改字体,更不用说怎么做了.

1)如果要右对齐数值,则必须将数字转换为字符串,并在字符串的左侧填充足够数量的空格.查看sprintf函数可用的各种选项. (左对齐以相同的方式完成,只有您在右边填充数字.
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.


计算显示区域的长度.(DispLen)
计算您的文字长度. (TextLen)
LeftMargin = DispLen-TextLen;

现在在您的文本之前添加空白LeftMargin时间,然后再打印.

希望对您有所帮助.
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.


这篇关于对齐文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆