使用C++实现格式化数据的IO

2014-11-24 07:57:43 · 作者: · 浏览: 0
print
#include    
 
#include
using namespace std;
void main()
{
char bookname[100];double price;int counts;
cout << "请输入书名:"<< endl;
cin>>bookname;
cout << "请输入单价:"<< endl;
cin>>price;
cout << "请输入销售数量:"<< endl;
cin>>counts;
cout<<"使用状态标志和成员函数进行格式化输出"<
cout<<"《"<
cout.width(5); //单价显示宽度为5个字符
cout.fill('*'); //宽度不满用*字符填充
cout<
#ifdef scientific
cout.setf(ios::scientific); //用科学记数法输出销售额
cout.precision(3); //保留3位精度
#else
cout<
cout<
#endif
cout.setf(ios::showpos|ios::left); //显示销售数量,带有正负号、左对齐
cout<
cout<<"使用流操作符进行格式输出"<
cout<<"《"<
<
<
<
cin>>bookname;
}


  
 

《VC++6.0示例程序光盘》实例代码