c++ - 如何在中使用 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('-')
填充了字符。'-'
我怎么解决这个问题?
解决方案
您再次需要setfill(' ')
像您的情况一样使用第二行。一旦我们使用setfill()
它,它将在我们使用的程序中设置为所有时间setw()
。
推荐阅读
- typescript - Discord 机器人消息问题
- javascript - DataTables - 导出数据中的所有列,无论表中可见什么
- c# - 为什么我新创建的方法没有出现在引用该方法所属类的不同类中?
- python-3.x - 如何使 pylint 为存储库中的所有函数和方法强制执行文档字符串
- c# - 在 asp.net 核心中添加文件夹路径而不是对其进行编码?
- python - 什么时候合并和连接两个熊猫数据框比较聪明?
- java - 如何显示 catch 和 finally 的异常?
- arrays - ruby 中两个不同数组的数组操作
- ios - UIViewRepresentable 不会更新我的 ios 图表数据集
- java - 如何在 intellij gradle 项目中只运行一个(当前)文件并忽略其他文件?