c++ - 如何使用 setw 格式化我的 ostringstream 的输出?
问题描述
我一直在尝试使用 setw 方法从我的程序中格式化我的输出但不工作?这是我的输出,国家之间的巨大差距(例如:美国):
我的代码如下所示:
string itemToString(const Country& i) {
ostringstream out;
out.setf(ios::fixed);
out.setf(ios::showpoint);
out.precision(2);
out << i.name
<< setw(20) << "|" << i.population
<< setw(10) << "|" << i.areaSQ
<< setw(10) << "|" << i.popDensitySQ
<< setw(10) << "|" << i.netMigration
<< setw(10) << "|" << i.GDP
<< setw(10) << "|" << i.literacy
<< setw(10) << "|" << i.birthRate << "\n";
return out.str();
}
我想看看我能做些什么来弥补美国等国家之间的巨大差距。
解决方案
推荐阅读
- android - 防止android tv行片段/浏览片段保存列表行中卡片的旧位置?
- python - python中的有序子集
- docker - Package.json file not found when using kubernetes
- mysql - Subtract two columns from two tables with Group By
- reactjs - Failed to compile ./src/index.js Module not found: Can't resolve 'react' in
- android - Circular Avatar ImageView with Text Layover at the bottom
- java - 使用 OAuth 到 Azure AD 的 Java WebApp - 获取个人资料图片?
- java - Gradle for Android:为什么 javaexec 不选择我的类路径?
- php - Laravel whereIn in array
- firebase - Can't select Firebase AB Testing Activation event nor Goal metric event