现在的位置: 首页 > 综合 > 正文

第十一周项目5-4-将数据写入文件

2014年11月23日 ⁄ 综合 ⁄ 共 911字 ⁄ 字号 评论关闭
/*                           
*程序的版权和版本声明部分:                           
*Copyright(c)2013,烟台大学计算机学院学生                           
*All rights reserved.                           
*文件名称:                           
*作者:田成琳                           
*完成日期:2013年 11月1 日                           
*版本号:v1.0                           
*对任务及求解方法的描述部分:                           
*输入描述:    
*问题描述:体验数据写入文档操作   
*程序输出:   
*问题分析:                           
*算法设计:                           
*/    
我的程序:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
    int a=354,b=1783,c=3701,d=3203,e=1139,max=100,min=1;
    double ave=71.4929;
    ofstream outfile("D:\\statictic.dat",ios::out);
    if(!outfile)
    {
        cerr<<"open error!"<<endl;
        exit(1);
    }
    string str1("最高分为:");
    string str2("最低分为:");
    string str3("平均分为:");
    string str4("优秀人数为:");
    string str5("良好人数为:");
    string str6("中等人数为:");
    string str7("及格人数为:");
    string str8("不及格人数为:");
    outfile<<str1<<" "<<max<<endl;
    outfile<<str2<<" "<<min<<endl;
    outfile<<str3<<" "<<ave<<endl;
    outfile<<str4<<" "<<a<<endl;
    outfile<<str5<<" "<<b<<endl;
    outfile<<str6<<" "<<c<<endl;
    outfile<<str7<<" "<<d<<endl;
    outfile<<str8<<" "<<e<<endl;
    outfile.close();
    return 0;
}

运行结果:
心得体会:这个和贺老师那个模板不太一样啊,贺老师那个模板是将输入的数据写入文件,前提需要cin,而这个题是直接将结果写入文件,无需cin,没办法,在网上找到了个这么个模板。。。

抱歉!评论已关闭.