#include<iostream>
#include<iomanip>
using namespace std;
#if 1
int main()
{
int a=21;
//cout.setf设置格式
cout.setf(ios::showbase);//为整数加一个进制前缀
cout<<"dec:"<<a<<endl;//十进制
cout.unsetf(ios:dec);//取消十进制格式设置
cout.setf(ios::hex);
cout<<"hex:"<<a<<endl;//十六进制
cout.unsetf(ios::hex);
cout.setf(ios::oct);
cout<<"oct:"<<a<<endl;//8进制
cout.unsetf(ios::oct);
const char *pt="jack";
//直接利用格式成员函数
cout.width(10);//指定域宽
cout<<pt<<endl;
cout.width(10);//一次性输出 每次都要设置
cout.fill('*');//用*填充
cout<<pt<<endl;
double pi=22.0/7.0;
cout<<pi<<endl;
cout.setf(ios::scientific);
cout<<pi<<endl;
cout.unsetf(ios::scientific);
//第三种 用流方式输出 四个字节宽度 右对齐 用0填充
cout<<setw(4)<<right<<setfill('0')<<1<<endl;
//显示前缀八进制
cout<<showbase<<oct<<21<<endl;
bool b=false;
cout<<b<<endl;
cout<<boolalpha<<b<<endl;
cout<<noboolalpha<<b<<endl;
return 0;
}
#endif //流格式化 记住五个常用
#if 0
//cout 标准输出对象(有缓冲区) cerr标准错误流(无缓冲区) clog标准错误流(有缓冲区)
//cout 输出可以重定向到一个文件中 cerr没缓冲区必须显示在显示器上
int main()
{
cout<<"cout"<<endl;
cerr<<"cerr"<<endl;
cerr<<"hello,world"<<endl;
return 0;
}
#endif//重定向
#if 0
{
cout<<"a";//没有清空缓冲区
cout<<"b"<<ends;//等于插了个\0字符
cout<<"c"<<endl;//等于插了个\n字符
cout<<"d"<<flush;//刷新缓冲区
//获取单个字符
char c=cin.get();
cout<<c<<endl;
cout.put(c);//输出一个字符
//const char* c="abc";//不行 必须为单个字符
//cout.put(c);
cout.put(c)<<endl;//换行
endl(cout<<"HELLO");//函数方式换行
//获取行
char str[200]={0,};//输入123 abc 只会读到123 后面的abc会在缓冲区里面
cin>>str;
cout<<str;
cin.getline(str,20);//(放哪里,获取大小)
cout<<str<<endl;
cin.getline(str,20,'/');没有/读满20个有/的话就到此为止
cout<<str<<endl;
return 0;
}
#endif//标准输入输出流