cout.precision(i);//输出精度为i的数据
for example:
i=0 ---------.>2
i=1 --------->2.1
i=4 -----------.>2.1235
cout.width(i);//就是输出的字符串宽度为i,不足的会用空格补足
cin.width();///输入字符串宽度
#include<iostream>
using namespace std;
int main()
{
int width = 4;
char str[20];
cout<<"please cout the :\n";
cin.width(5);
while(cin>>str)
{
cout.width(width++);
cout<<str<<endl;
cin.width(5);
}
return 0;
}
输出:
please cout the :
i love you so much!i like you!
i
love
you
so
much
!i
like
you!