cout.width 的反转是什么? (C++)
我正在尝试 std::cout.width(int) 来看看它做了什么,它将文本向右推以填充最小宽度:
TH
变成:
TH
填充最小宽度 10。我想知道如果A)有办法扭转这种情况,在文本后面放置一些空格来填充最小宽度,并且B)有没有办法创建最大宽度和最小宽度?
顺便说一句,是否可以创建一个从 cout
或 ostream
派生的类?
I was trying std::cout.width(int)
to see what it did, and it pushes the text right to fill a minimum width:
TH
becomes:
TH
to fill a minimum width of 10. I am wondering if A) there is a way to reverse this, have a number of spaces put AFTER the text to fill a minimum width, and B) is there a way to create a maximum width AND a minimum width?
And on a lesser note, is it possible to create a class derived from cout
or ostream
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
宽度设置您接下来要使用 cout 打印的内容的“列”大小。
将在您创建的列中将上面的内容打印为“左”对齐。
默认情况下,不同的“类型”与某些边对齐。
有关此参考页面的更多信息。
Width sets the "column" size for what you are printing next with cout.
would print the above as "left" aligned in the column you made.
Different "types" are aligned to certain sides by default.
More info on this reference page.
一次提出一个问题是个好主意,但您不能从 cout 派生,因为它是一个实例,而不是一个类。 有关派生新输出流类型的详细信息,请阅读本书。
One question at a time is a good idea, but you can't derive from cout because it is an instance, not a class. For details of deriving a new output stream type, read this book.