iomanip的控制符
resetiosflags(long f) 关闭由参数f指定的格式标志,用于输入输出
setprecision(int n) 设置数据小数位数,缺省时为6,用于输入输出
setw(int n) 设置域宽,用于输入输出
cout << setiosflags(ios::fixed) << setprecision(2)<< a << endl;
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
for(int i=1;i<=7;i++){
cout<<setfill(' ')<<setw(i)<<" ";
cout<<setfill('m')<<setw(15-2*i)<<"m";
cout<<setfill(' ')<<setw(i)<<" "<<endl;
}
}
![](https://img-blog.csdnimg.cn/63a7cb9933984d959822a3d3fb096e9b.png)
文件I/O流
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
ifstream f1;
ofstream f2;
f1.open("testin.txt");
f2.open("testout.txt");
char c;
while(f1){
f1.get(c);
f2<<c;
}
f1.close();
f2.close();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)