/*
*程序的版权和版本声明部分:
*Copyright(c)2013,烟台大学计算机学院学生
*All rights reserved.
*文件名称:
*作者:田成琳
*完成日期:2013年 11月1 日
*版本号:v1.0
*对任务及求解方法的描述部分:
*输入描述:
*问题描述:体验文档读入操作
*程序输出:
*问题分析:
*算法设计:
*/
我的程序:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
int a,b,c,d,e;
cout<<"请输入优秀人数:"<<endl;
cin>>a;
cout<<"请输入良好人数:"<<endl;
cin>>b;
cout<<"请输入中等人数:"<<endl;
cin>>c;
cout<<"请输入及格人数:"<<endl;
cin>>d;
cout<<"请输入不及格人数:"<<endl;
cin>>e;
ofstream outfile("D:\\statictic.dat",ios::out);
if(!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}
string str4("优秀人数为:");
string str5("良好人数为:");
string str6("中等人数为:");
string str7("及格人数为:");
string str8("不及格人数为:");
outfile<<str4<<" "<<a<<endl;
outfile<<str5<<" "<<b<<endl;
outfile<<str6<<" "<<c<<endl;
outfile<<str7<<" "<<d<<endl;
outfile<<str8<<" "<<e<<endl;
outfile.close();
return 0;
}
运行结果:
心得体会:那个string挺好用的,尽管不知道是干嘛的。