C++11 显示结果c++;程序
我需要有关setw()的帮助。我有一种烟:C++11 显示结果c++;程序,c++11,C++11,我需要有关setw()的帮助。我有一种烟: void PrintRecord(PLAYER &m, ostream &cout) { cout << setw(3) << m.PlayerID << '\t' << m.LastName << ',' << setw(4) << m.FirstName; if ( m.Hits > 0 || m.Walks
void PrintRecord(PLAYER &m, ostream &cout)
{
cout << setw(3) << m.PlayerID << '\t' << m.LastName << ',' << setw(4)
<< m.FirstName;
if ( m.Hits > 0 || m.Walks > 0 || m.Outs > 0 )
{
cout << "\t\t" << setprecision(3) << fixed << m.Hits << '\t'
<< m.Walks << '\t' << m.Outs << '\t' << m.BattingAvg
<< '\t' << m.OnBaseAvg << endl;
}
else
{
cout << endl;
}
}
void打印记录(PLAYER&m、ostream&cout)
{
cout您应该在打印每个值之前通过调用setw
为列中的每个值设置相同的宽度。通常在使用setw
时不需要使用“\t”。与setprecision
不同,setw
不是“粘性”的,因此您需要在每个打印值之前设置它
cout << setw(3) << m.PlayerID << setw(20) << m.LastName << ',' << setw(20)
<< m.FirstName;
if ( m.Hits > 0 || m.Walks > 0 || m.Outs > 0 )
{
cout << setw(20) << setprecision(3) << fixed << m.Hits << setw(20)
<< m.Walks << setw(20) << m.Outs << setw(20) << m.BattingAvg
<< setw(20) << m.OnBaseAvg << endl;
}
无法查看cstdio中的printf。它允许您格式化输出。