cout 如何像printf一样实现输出对齐
cout 如何像printf一样实现输出对齐程序代码:
#include<iostream> using namespace std; void calc(short r, float *pper, float *parea) { *pper = (2.0*(r+1.0)*3.1415926) - (2.0*r*3.1415926); *parea = 3.1415926*(r+1.0)*(r+1.0) - 3.1415926*r*r; } int main() { float per_dif, area; for(short rad=1; rad<=10; rad++) { calc(rad, &per_dif, &area); printf("当外圆半径R= %2d 内圆半径r= %2d 外圆、内圆周长差L= %7.5f 圆环面积S= %8.5f\n",rad+1,rad,per_dif,area); } cout<<endl<<endl; for(short rad=1; rad<=10; rad++) { calc(rad, &per_dif, &area); cout<<"当外圆半径R= "<<rad+1<<" 内圆半径r= "<<rad<<" 外圆、内圆周长差L= "<<per_dif<<" 圆环面积S= "<<area<<endl; } }