/*
7
7.6669okwari
7.6669 0okwari
sun
sfa6+5+7
88
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;
}
C++ I/0 Stream <setf and Manipulators>
最新推荐文章于 2025-04-08 13:29:43 发布