1:代码如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
// 2.10.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <iostream> using namespace std; void main() { int x=123; double y=-3.1415; cout << "x="; cout.width(10);//输出字符串的宽度为10 cout << x; cout << "y="; cout.width(10);//输出字符串的宽度为10 cout << y <<endl; cout.setf(ios::left);//输出数据在本域宽范围内向左对齐 cout << "x="; cout.width(10);//输出字符串的宽度为10 cout << x; cout << "y="; cout << y <<endl; cout.fill('*');//在空余处用*填充 cout.precision(4);//取4位有效数字 cout.setf(ios::showpos);//强制显示符号 cout << "x="; cout.width(10);//输出宽度设为10 cout << x; cout << "y="; cout.width(10);//输出宽度设为10 cout << y <<endl; }
运行结果: