用流控制成员函数输出数据

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 int main(int argc, char** argv) {
 6     int a=21;
 7     cout.setf(ios::showbase);
 8     cout<<"dec:"<<a<<endl;
 9     cout.unsetf(ios::dec);
10     cout.setf(ios::hex);
11     cout<<"hex:"<<a<<endl;
12     cout.unsetf(ios::hex);
13     cout.setf(ios::oct);
14     cout<<"oct:"<<a<<endl;
15     cout.unsetf(ios::oct);
16     char *pt="China";
17     cout.width(10);
18     cout<<pt<<endl;
19     cout.width(10);
20     cout.fill('*');
21     cout<<pt<<endl;
22     double pi=22.0/7.0;
23     cout.setf(ios::scientific);
24     cout<<"pi=";
25     cout.width(14);
26     cout.width(14);
27     cout<<pi<<endl;
28     cout.unsetf(ios::scientific);
29     cout.setf(ios::fixed);
30     cout.width(12);
31     cout.setf(ios::showpos);
32     cout.setf(ios::internal);
33     cout.precision(6);
34     cout<<pi<<endl;
35     return 0;
36 }
原文地址:https://www.cnblogs.com/borter/p/9405524.html