C++ I/0 Stream <setf and Manipulators>

来源:互联网 发布:中文翻译英文软件下载 编辑:程序博客网 时间:2024/04/27 15:25
/*  77.6669okwari7.6669 0okwarisunsfa6+5+788  7 hello!*  123*123  *  123**/#include <iostream>#include <fstream>#include <iomanip>using namespace std;int main() {    cout.width(3);    cout << 7 << endl;    cout.width(5);    cout << 7.6669  << "okwari" << endl;    cout.width(5);    cout << 7.6669 <<  cout.width(2) << "okwari" << endl; // cout.width(2) 返回值为0;所以输出0okwari    cout.width(3);    cout << "sun" << endl;    cout.setf(ios::showpos); // 当出现数字时自动在其前面加上一个”加号“,对字符串中的数字无效果    cout << "sfa6" << 5 << 7 << endl;    cout.unsetf(ios::showpos); // 取消加号设置    cout << 88 << endl;    cout << setw(3) << 7 << setw(7) << "hello!" << endl; // 使用setw()需包含头文件 iomanip    cout << "*" << setw(5) << 123;    cout.setf(ios::left);    cout << "*" << setw(5) << 123;    cout.setf(ios::right);    cout << "*" << setw(5) << 123 << "*" << endl;    return 0;}
0 0