操纵器改变ostream
. 因此,它们应该在要求流输出某些内容之前应用。
在你的情况下,你问:
- 格式化下一个输出左侧
- 格式化下一个输出,大小为 6 个字符
- 输出“你好”
因此,流输出单词“hello”,后跟 1 个空格以达到大小 6,正如操纵器序列所要求的那样。
你可以在那里找到参考资料:
我引用最重要的句子std::left + operator <<
:
if (os.flags() & ios_base::adjustfield) == ios_base::left,将 os.width()-str.size() 字符的 os.fill() 副本放在字符序列之后
并且std::setw
:
The width property of the stream will be reset to zero (meaning "unspecified") if any of the following functions are called:
Input
operator>>(basic_istream&, basic_string&)
operator>>(basic_ostream&, char*)
Output
Overloads 1-7 of basic_ostream::operator<<() (at Stage 3 of num_put::put())
operator<<(basic_ostream&, char) and operator<<(basic_ostream&, char*)
operator<<(basic_ostream&, basic_string&)
std::put_money (inside money_put::put())
std::quoted (when used with an output stream)