C++中设置值的宽度,使用setw函数。 如: #include<iomanip> cout<<setw(4)<<2<<setw(3)<<4<<endl; 输出:2空格空格空格 4空格空格 即2占4位,4占3位。