std:: left, std:: right, std:: internal
|
定义于头文件
<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) | |
修改输出流中填充字符的定位方式。
left
和
right
适用于所有输出类型,
internal
适用于整型、浮点型和货币数值输出。对输入操作无影响。
adjustfield
设置为
left
,如同调用
str.
setf
(
std::
ios_base
::
left
,
std::
ios_base
::
adjustfield
)
。
adjustfield
为
right
,如同调用
str.
setf
(
std::
ios_base
::
right
,
std::
ios_base
::
adjustfield
)
。
adjustfield
为
internal
,如同调用
str.
setf
(
std::
ios_base
::
internal
,
std::
ios_base
::
adjustfield
)
。
标准流的初始默认设置等同于
right
。
这是一个I/O操纵器。它可以像
out
<<
std
::
left
这样被调用,其中
out
是
std::basic_ostream
类型的对象;或者像
in
>>
std
::
left
这样被调用,其中
in
是
std::basic_istream
类型的对象。
目录 |
参数
| str | - | I/O 流的引用 |
返回值
str (指向经过操作后的流的引用)。
示例
#include <iomanip> #include <iostream> #include <locale> int main() { std::cout.imbue(std::locale("en_US.utf8")); std::cout << "默认定位:\n" << 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 << "左对齐定位:\n" << std::left << std::setw(12) << -1.23 << '\n' << std::setw(12) << 42 << '\n' << std::setw(12) << std::put_money(123, true) << "\n\n"; std::cout << "内部定位:\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 << "右对齐定位:\n" << std::right << std::setw(12) << -1.23 << '\n' << std::setw(12) << 42 << '\n' << std::setw(12) << std::put_money(123, true) << '\n'; }
输出:
默认定位: *******-1.23 ********0x2a ***USD *1.23 左对齐定位: -1.23******* 0x2a******** USD *1.23*** 内部定位: -*******1.23 0x********2a USD ****1.23 右对齐定位: *******-1.23 ********0x2a ***USD *1.23
参见
|
更改下一个输入/输出字段的宽度
(函数) |
|
|
更改填充字符
(函数模板) |
|
|
控制是否使用前缀指示数值进制
(函数) |