标题:新的一天是吧
关键词:标准输出流
内容
A. 一句话概括今日目标完成情况
(a)标准输出流的学习 100%
(b)无
B.具体内容
标准输出设备就是显示器
cout是ostream类的一个对象,<<就是流插入运算符
put 无格式插入一个字节
write 无格式插入一字节序列
flush 刷新输出流
seekp 移动输出流指针
tellp 返回输出流中置顶位置的指针值
这是一些常用的函数
然后学习了 setf unsetf width precision fill 这几个 成员函数,然后学习了ios类的一些常用状态标志。
实践了以下内容
#include<iostream>
using namespace std;
int main()
{
cout.setf(ios::left|ios::showpoint);
cout.precision(5);
cout<<123.456789<<endl;
cout.width(10);
cout.fill('*');
cout.unsetf(ios::left);
cout.setf(ios::right);
cout<<123.456789<<endl;
cout.setf(ios::left|ios::fixed);
cout.precision(3);
cout<<999.123456<<endl;
cout<<99.123456<<endl;
cout.unsetf(ios::left|ios::fixed);
cout.setf(ios::left|ios::scientific);
cout<<123.45678<<endl;
return 0;
}
真特么奇妙
然后是用setiosflags这些函数来控制输出格式
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int a=128;
cout<<"dec: "<<dec<<a<<endl;
cout<<"hex: "<<hex<<a<<endl;
cout<<"oct: "<<oct<<a<<endl<<endl;
char pt[]="Xi'an";
cout<<setw(10)<<pt<<endl;
cout<<setfill('*')<<setw(10)<<pt<<endl<<endl;
double B=27.123456789;
cout<<setiosflags(ios::scientific)<<setprecision(8);
cout<<"B= "<<B<<endl;
cout<<"B= "<<setprecision(4)<<B<<endl;
cout<<resetiosflags(ios::scientific);
cout<<"B= "<<setiosflags(ios::fixed)<<setprecision(6)<<B;
cout<<endl<<"Thanks for using!"<<endl;
return 0;
}
C.明日计划