Output aligned columns

匆匆过客 提交于 2019-11-29 04:52:29

In the class employee of print employee method: Use this line to print.

cout << setw(20) << left << surname << setw(10) << left << empNumber << setw(4) << hourlyRate << endl;

You forgot to add "<< left". This is required if you want left aligned.

Hope it ll useful.

You need to set a width before you print out the name to get other things to line up after that. Something on this general order:

cout << left << setw(15) << surname 
     << setw(10) << empNumber << "\t" 
     << setw(4) << hourlyRate << "\n";

I'd (at least normally) avoid trying to mix fixed-width fields with tabs as well. It's generally easier to just use widths to align things.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!