std::left, std::right, std::internal
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <ios> 中定义
|
||
std::ios_base& left( std::ios_base& str ); |
(1) | |
std::ios_base& right( std::ios_base& str ); |
(2) | |
std::ios_base& internal( std::ios_base& str ); |
(3) | |
修改的填充字符的默认定位。
1) left
和right
适用于任何输出,internal
适用于整数,浮点,货币输出。有没有对输入的影响.原文:
Modifies the default positioning of the fill characters.
left
and right
apply to any output, internal
applies to integer, floating-point, and monetary output. Has no effect on input.设置
2) adjustfield
的流str
left
仿佛通过调用str.setf(std::ios_base::left, std::ios_base::adjustfield)原文:
sets the
adjustfield
of the stream str
to left
as if by calling str.setf(std::ios_base::left, std::ios_base::adjustfield)设置
3) adjustfield
的流str
right
仿佛通过调用str.setf(std::ios_base::right, std::ios_base::adjustfield)原文:
sets the
adjustfield
of the stream str
to right
as if by calling str.setf(std::ios_base::right, std::ios_base::adjustfield)设置
adjustfield
的流str
internal
仿佛通过调用str.setf(std::ios_base::internal, std::ios_base::adjustfield)原文:
sets the
adjustfield
of the stream str
to internal
as if by calling str.setf(std::ios_base::internal, std::ios_base::adjustfield)这是一个I / O操纵器,它可被称为与表达式如out << std::left类型
out
任何std::basic_ostream,或与一个表达式如in >> std::left类型in
任何std::basic_istream.原文:
This is an I/O manipulator, it may be called with an expression such as out << std::left for any
out
of type std::basic_ostream or with an expression such as in >> std::left for any in
of type std::basic_istream.目录 |
[编辑] 参数
str | - | 参考I / O流
|
[编辑] 返回值
str
(参考操作后到流)原文:
str
(reference to the stream after manipulation)[编辑] 示例
#include <iostream> #include <iomanip> #include <locale> int main() { std::cout.imbue(std::locale("en_US.utf8")); std::cout << "Left fill:\n" << std::left << std::setfill('*') << std::setw(12) << -1.23 << '\n' << std::setw(12) << std::hex << std::showbase << 42 << '\n' << std::setw(12) << std::put_money(123, true) << "\n\n"; std::cout << "Internal fill:\n" << std::internal << std::setw(12) << -1.23 << '\n' << std::setw(12) << 42 << '\n' << std::setw(12) << std::put_money(123, true) << "\n\n"; std::cout << "Right fill:\n" << std::right << std::setw(12) << -1.23 << '\n' << std::setw(12) << 42 << '\n' << std::setw(12) << std::put_money(123, true) << '\n'; }
输出:
Left fill: -1.23******* 0x2a******** USD *1.23*** Internal fill: -*******1.23 0x********2a USD ****1.23 Right fill: *******-1.23 ********0x2a ***USD *1.23
[编辑] 另请参阅
改变宽度的下一个输入/输出字段 原文: changes the width of the next input/output field (函数) | |
改变填充字符 (函数模板) |