首页 > 解决方案 > 如何在中使用 setfill()更流利?

问题描述

今天学习了setfill()中的 等方法#include<iomanip>,所以对使用 进行了练习#include<iomanip>

我想在控制台上打印这个:

+--------------+         
| Iomanip 示例 |  
+--------------+         

所以我写了这段代码:

cout << '+' << setfill('-') << setw(25) << '+' << endl;
cout << setw(26) << internal << "Iomanip Examples" << endl;
cout << '+' << setfill('-') << setw(25) << '+' << endl;

但我的控制台打印了这个:

+---------------+ //没关系。  
------Iomanip 例子 //nope..  
+---------------+  

我想当我使用时,输出流在空格中setfill('-')填充了字符。'-'

我怎么解决这个问题?

标签: c++iomanip

解决方案


您再次需要setfill(' ')像您的情况一样使用第二行。一旦我们使用setfill()它,它将在我们使用的程序中设置为所有时间setw()


推荐阅读