今天,我了解了setfill()
和#include<iomanip>
中的其他方法,因此我有使用#include<iomanip>
的练习。
我想在控制台上打印它:
+-------------------------+ | Iomanip Examples | +-------------------------+
So I wrote this code:
cout << '+' << setfill('-') << setw(25) << '+' << endl;
cout << setw(26) << internal << "Iomanip Examples" << endl;
cout << '+' << setfill('-') << setw(25) << '+' << endl;
但是我的控制台打印了这个:+ --------------------------- + //没关系。
------ Iomanip示例//不。
+ --------------------------- +
我认为当我使用
setfill('-')
时,输出流在空白处填充了'-'
字符。我怎么解决这个问题?
最佳答案
您仍然需要根据情况选择setfill(' ')
作为第二行。
一旦我们使用setfill()
,它将在我们使用setw()
的程序中永久设置。
关于c++ - 如何更流畅地使用<iomanip>中的setfill()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64475240/